cmdutils: allow matching by metadata in stream specifiers
[ffmpeg.git] / libavformat / r3d.c
index f67d10e..74a1f2b 100644 (file)
@@ -19,8 +19,6 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-//#define DEBUG
-
 #include "libavutil/intreadwrite.h"
 #include "libavutil/dict.h"
 #include "libavutil/mathematics.h"
@@ -62,7 +60,7 @@ static int r3d_read_red1(AVFormatContext *s)
     if (!st)
         return AVERROR(ENOMEM);
     st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
-    st->codec->codec_id = CODEC_ID_JPEG2000;
+    st->codec->codec_id = AV_CODEC_ID_JPEG2000;
 
     tmp  = avio_r8(s->pb); // major version
     tmp2 = avio_r8(s->pb); // minor version
@@ -87,8 +85,9 @@ static int r3d_read_red1(AVFormatContext *s)
 
     framerate.num = avio_rb16(s->pb);
     framerate.den = avio_rb16(s->pb);
-    if (framerate.num && framerate.den)
-        st->r_frame_rate = st->avg_frame_rate = framerate;
+    if (framerate.num > 0 && framerate.den > 0) {
+        st->avg_frame_rate = framerate;
+    }
 
     tmp = avio_r8(s->pb); // audio channels
     av_dlog(s, "audio channels %d\n", tmp);
@@ -97,7 +96,7 @@ static int r3d_read_red1(AVFormatContext *s)
         if (!ast)
             return AVERROR(ENOMEM);
         ast->codec->codec_type = AVMEDIA_TYPE_AUDIO;
-        ast->codec->codec_id = CODEC_ID_PCM_S32BE;
+        ast->codec->codec_id = AV_CODEC_ID_PCM_S32BE;
         ast->codec->channels = tmp;
         avpriv_set_pts_info(ast, 32, 1, st->time_base.den);
     }
@@ -135,10 +134,10 @@ static int r3d_read_rdvo(AVFormatContext *s, Atom *atom)
         av_dlog(s, "video offset %d: %#x\n", i, r3d->video_offsets[i]);
     }
 
-    if (st->r_frame_rate.num)
+    if (st->avg_frame_rate.num)
         st->duration = av_rescale_q(r3d->video_offsets_count,
-                                    (AVRational){st->r_frame_rate.den,
-                                                 st->r_frame_rate.num},
+                                    (AVRational){st->avg_frame_rate.den,
+                                                 st->avg_frame_rate.num},
                                     st->time_base);
     av_dlog(s, "duration %"PRId64"\n", st->duration);
 
@@ -262,9 +261,9 @@ static int r3d_read_redv(AVFormatContext *s, AVPacket *pkt, Atom *atom)
 
     pkt->stream_index = 0;
     pkt->dts = dts;
-    if (st->r_frame_rate.num)
+    if (st->avg_frame_rate.num)
         pkt->duration = (uint64_t)st->time_base.den*
-            st->r_frame_rate.den/st->r_frame_rate.num;
+            st->avg_frame_rate.den/st->avg_frame_rate.num;
     av_dlog(s, "pkt dts %"PRId64" duration %d\n", pkt->dts, pkt->duration);
 
     return 0;
@@ -282,6 +281,10 @@ static int r3d_read_reda(AVFormatContext *s, AVPacket *pkt, Atom *atom)
     dts = avio_rb32(s->pb);
 
     st->codec->sample_rate = avio_rb32(s->pb);
+    if (st->codec->sample_rate <= 0) {
+        av_log(s, AV_LOG_ERROR, "Bad sample rate\n");
+        return AVERROR_INVALIDDATA;
+    }
 
     samples = avio_rb32(s->pb);
 
@@ -362,11 +365,11 @@ static int r3d_seek(AVFormatContext *s, int stream_index, int64_t sample_time, i
     R3DContext *r3d = s->priv_data;
     int frame_num;
 
-    if (!st->r_frame_rate.num)
+    if (!st->avg_frame_rate.num)
         return -1;
 
     frame_num = av_rescale_q(sample_time, st->time_base,
-                             (AVRational){st->r_frame_rate.den, st->r_frame_rate.num});
+                             (AVRational){st->avg_frame_rate.den, st->avg_frame_rate.num});
     av_dlog(s, "seek frame num %d timestamp %"PRId64"\n",
             frame_num, sample_time);
 
@@ -392,7 +395,7 @@ static int r3d_close(AVFormatContext *s)
 
 AVInputFormat ff_r3d_demuxer = {
     .name           = "r3d",
-    .long_name      = NULL_IF_CONFIG_SMALL("REDCODE R3D format"),
+    .long_name      = NULL_IF_CONFIG_SMALL("REDCODE R3D"),
     .priv_data_size = sizeof(R3DContext),
     .read_probe     = r3d_probe,
     .read_header    = r3d_read_header,