]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/oma.c
mpegts: replace some magic numbers with the existing define
[ffmpeg] / libavformat / oma.c
index da014689d027e98e09522496e5de205b9407410a..1aa9a254773b120a5ec513a4d1c894409d81886c 100644 (file)
@@ -41,6 +41,7 @@
  */
 
 #include "avformat.h"
+#include "internal.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/des.h"
 #include "pcm.h"
@@ -60,9 +61,10 @@ enum {
 };
 
 static const AVCodecTag codec_oma_tags[] = {
-    { CODEC_ID_ATRAC3,  OMA_CODECID_ATRAC3 },
-    { CODEC_ID_ATRAC3P, OMA_CODECID_ATRAC3P },
-    { CODEC_ID_MP3,     OMA_CODECID_MP3 },
+    { CODEC_ID_ATRAC3,      OMA_CODECID_ATRAC3 },
+    { CODEC_ID_ATRAC3P,     OMA_CODECID_ATRAC3P },
+    { CODEC_ID_MP3,         OMA_CODECID_MP3 },
+    { CODEC_ID_PCM_S16BE,   OMA_CODECID_LPCM },
 };
 
 static const uint64_t leaf_table[] = {
@@ -201,8 +203,8 @@ static int decrypt_init(AVFormatContext *s, ID3v2ExtraMeta *em, uint8_t *header)
     while (em) {
         if (!strcmp(em->tag, "GEOB") &&
             (geob = em->data) &&
-            !strcmp(geob->description, "OMG_LSI") ||
-            !strcmp(geob->description, "OMG_BKLSI")) {
+            (!strcmp(geob->description, "OMG_LSI") ||
+             !strcmp(geob->description, "OMG_BKLSI"))) {
             break;
         }
         em = em->next;
@@ -343,20 +345,30 @@ static int oma_read_header(AVFormatContext *s,
             AV_WL16(&edata[10], 1);             // always 1
             // AV_WL16(&edata[12], 0);          // always 0
 
-            av_set_pts_info(st, 64, 1, st->codec->sample_rate);
+            avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
             break;
         case OMA_CODECID_ATRAC3P:
             st->codec->channels = (codec_params >> 10) & 7;
             framesize = ((codec_params & 0x3FF) * 8) + 8;
             st->codec->sample_rate = srate_tab[(codec_params >> 13) & 7]*100;
             st->codec->bit_rate    = st->codec->sample_rate * framesize * 8 / 1024;
-            av_set_pts_info(st, 64, 1, st->codec->sample_rate);
+            avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
             av_log(s, AV_LOG_ERROR, "Unsupported codec ATRAC3+!\n");
             break;
         case OMA_CODECID_MP3:
             st->need_parsing = AVSTREAM_PARSE_FULL;
             framesize = 1024;
             break;
+        case OMA_CODECID_LPCM:
+            /* PCM 44.1 kHz 16 bit stereo big-endian */
+            st->codec->channels = 2;
+            st->codec->sample_rate = 44100;
+            framesize = 1024;
+            /* bit rate = sample rate x PCM block align (= 4) x 8 */
+            st->codec->bit_rate = st->codec->sample_rate * 32;
+            st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id);
+            avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
+            break;
         default:
             av_log(s, AV_LOG_ERROR, "Unsupported codec %d!\n",buf[32]);
             return -1;
@@ -393,14 +405,20 @@ static int oma_read_probe(AVProbeData *p)
     unsigned tag_len = 0;
 
     buf = p->buf;
-    /* version must be 3 and flags byte zero */
-    if (ff_id3v2_match(buf, ID3v2_EA3_MAGIC) && buf[3] == 3 && !buf[4])
-        tag_len = ff_id3v2_tag_len(buf);
 
-    // This check cannot overflow as tag_len has at most 28 bits
-    if (p->buf_size < tag_len + 5)
+    if (p->buf_size < ID3v2_HEADER_SIZE ||
+        !ff_id3v2_match(buf, ID3v2_EA3_MAGIC) ||
+        buf[3] != 3 || // version must be 3
+        buf[4]) // flags byte zero
         return 0;
 
+    tag_len = ff_id3v2_tag_len(buf);
+
+    /* This check cannot overflow as tag_len has at most 28 bits */
+    if (p->buf_size < tag_len + 5)
+        /* EA3 header comes late, might be outside of the probe buffer */
+        return AVPROBE_SCORE_MAX / 2;
+
     buf += tag_len;
 
     if (!memcmp(buf, "EA3", 3) && !buf[4] && buf[5] == EA3_HEADER_SIZE)