]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/dv1394.c
better warning
[ffmpeg] / libavformat / dv1394.c
index 1cbb0e7eb1bf5adee32c898c9785f2fc262e664b..f00d474357640a2eddafdf1bf3fffd923408a29d 100644 (file)
@@ -2,19 +2,21 @@
  * Linux DV1394 interface
  * Copyright (c) 2003 Max Krasnyansky <maxk@qualcomm.com>
  *
- * This library is free software; you can redistribute it and/or
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This library is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <unistd.h>
@@ -43,14 +45,12 @@ struct dv1394_data {
     int avail;  /* Number of frames available for reading */
     int done;   /* Number of completed frames */
 
-    int64_t pts;  /* Current timestamp */
-
     DVDemuxContext* dv_demux; /* Generic DV muxing/demuxing context */
 };
 
-/* 
+/*
  * The trick here is to kludge around well known problem with kernel Ooopsing
- * when you try to capture PAL on a device node configure for NTSC. That's 
+ * when you try to capture PAL on a device node configure for NTSC. That's
  * why we have to configure the device node for PAL, and then read only NTSC
  * amount of data.
  */
@@ -90,9 +90,9 @@ static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap
         goto failed;
 
     if (ap->standard && !strcasecmp(ap->standard, "pal"))
-       dv->format = DV1394_PAL;
+        dv->format = DV1394_PAL;
     else
-       dv->format = DV1394_NTSC;
+        dv->format = DV1394_NTSC;
 
     if (ap->channel)
         dv->channel = ap->channel;
@@ -121,8 +121,6 @@ static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap
         goto failed;
     }
 
-    av_set_pts_info(context, 48, 1, 1000000);
-
     if (dv1394_start(dv) < 0)
         goto failed;
 
@@ -130,7 +128,7 @@ static int dv1394_read_header(AVFormatContext * context, AVFormatParameters * ap
 
 failed:
     close(dv->fd);
-    return -EIO;
+    return AVERROR_IO;
 }
 
 static int dv1394_read_packet(AVFormatContext *context, AVPacket *pkt)
@@ -140,7 +138,7 @@ static int dv1394_read_packet(AVFormatContext *context, AVPacket *pkt)
 
     size = dv_get_packet(dv->dv_demux, pkt);
     if (size > 0)
-        goto out;
+        return size;
 
     if (!dv->avail) {
         struct dv1394_status s;
@@ -152,9 +150,9 @@ static int dv1394_read_packet(AVFormatContext *context, AVPacket *pkt)
                 /* This usually means that ring buffer overflowed.
                  * We have to reset :(.
                  */
-  
-                fprintf(stderr, "DV1394: Ring buffer overflow. Reseting ..\n");
+
+                av_log(context, AV_LOG_ERROR, "DV1394: Ring buffer overflow. Reseting ..\n");
+
                 dv1394_reset(dv);
                 dv1394_start(dv);
             }
@@ -169,15 +167,15 @@ restart_poll:
             if (errno == EAGAIN || errno == EINTR)
                 goto restart_poll;
             perror("Poll failed");
-            return -EIO;
+            return AVERROR_IO;
         }
 
         if (ioctl(dv->fd, DV1394_GET_STATUS, &s) < 0) {
             perror("Failed to get status");
-            return -EIO;
+            return AVERROR_IO;
         }
 #ifdef DV1394_DEBUG
-        fprintf(stderr, "DV1394: status\n"
+        av_log(context, AV_LOG_DEBUG, "DV1394: status\n"
                 "\tactive_frame\t%d\n"
                 "\tfirst_clear_frame\t%d\n"
                 "\tn_clear_frames\t%d\n"
@@ -191,7 +189,7 @@ restart_poll:
         dv->done  = 0;
 
         if (s.dropped_frames) {
-            fprintf(stderr, "DV1394: Frame drop detected (%d). Reseting ..\n",
+            av_log(context, AV_LOG_ERROR, "DV1394: Frame drop detected (%d). Reseting ..\n",
                     s.dropped_frames);
 
             dv1394_reset(dv);
@@ -200,19 +198,16 @@ restart_poll:
     }
 
 #ifdef DV1394_DEBUG
-    fprintf(stderr, "index %d, avail %d, done %d\n", dv->index, dv->avail,
+    av_log(context, AV_LOG_DEBUG, "index %d, avail %d, done %d\n", dv->index, dv->avail,
             dv->done);
 #endif
 
-    size = dv_produce_packet(dv->dv_demux, pkt, 
-                             dv->ring + (dv->index * DV1394_PAL_FRAME_SIZE), 
-                            DV1394_PAL_FRAME_SIZE);
+    size = dv_produce_packet(dv->dv_demux, pkt,
+                             dv->ring + (dv->index * DV1394_PAL_FRAME_SIZE),
+                             DV1394_PAL_FRAME_SIZE);
     dv->index = (dv->index + 1) % DV1394_RING_FRAMES;
     dv->done++; dv->avail--;
-    dv->pts = av_gettime() & ((1LL << 48) - 1);
-    
-out:
-    pkt->pts = dv->pts;
+
     return size;
 }
 
@@ -234,7 +229,7 @@ static int dv1394_close(AVFormatContext * context)
     return 0;
 }
 
-static AVInputFormat dv1394_format = {
+AVInputFormat dv1394_demuxer = {
     .name           = "dv1394",
     .long_name      = "dv1394 A/V grab",
     .priv_data_size = sizeof(struct dv1394_data),
@@ -243,9 +238,3 @@ static AVInputFormat dv1394_format = {
     .read_close     = dv1394_close,
     .flags          = AVFMT_NOFILE
 };
-
-int dv1394_init(void)
-{
-    av_register_input_format(&dv1394_format);
-    return 0;
-}