]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/mpc.c
Add support for http digest authentication
[ffmpeg] / libavformat / mpc.c
index 03aa7f0d57633835ecf9f22848d037479e0785bc..a16478300219fc6b90cc879cc74e9cfdd80951e2 100644 (file)
@@ -58,26 +58,32 @@ static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap)
 {
     MPCContext *c = s->priv_data;
     AVStream *st;
-    int t;
+    int t, ret;
+    int64_t pos = url_ftell(s->pb);
 
     t = get_le24(s->pb);
     if(t != MKTAG('M', 'P', '+', 0)){
-        if(t != MKTAG('I', 'D', '3', 0)){
+        uint8_t buf[ID3v2_HEADER_SIZE];
+        if (url_fseek(s->pb, pos, SEEK_SET) < 0)
+            return -1;
+        ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE);
+        if (ret != ID3v2_HEADER_SIZE || !ff_id3v2_match(buf)) {
             av_log(s, AV_LOG_ERROR, "Not a Musepack file\n");
             return -1;
         }
         /* skip ID3 tags and try again */
-        url_fskip(s->pb, 3);
-        t  = get_byte(s->pb) << 21;
-        t |= get_byte(s->pb) << 14;
-        t |= get_byte(s->pb) <<  7;
-        t |= get_byte(s->pb);
+        t = ff_id3v2_tag_len(buf) - ID3v2_HEADER_SIZE;
         av_log(s, AV_LOG_DEBUG, "Skipping %d(%X) bytes of ID3 data\n", t, t);
         url_fskip(s->pb, t);
         if(get_le24(s->pb) != MKTAG('M', 'P', '+', 0)){
             av_log(s, AV_LOG_ERROR, "Not a Musepack file\n");
             return -1;
         }
+        /* read ID3 tags */
+        if (url_fseek(s->pb, pos, SEEK_SET) < 0)
+            return -1;
+        ff_id3v2_read(s);
+        get_le24(s->pb);
     }
     c->ver = get_byte(s->pb);
     if(c->ver != 0x07 && c->ver != 0x17){
@@ -109,8 +115,8 @@ static int mpc_read_header(AVFormatContext *s, AVFormatParameters *ap)
     st->codec->sample_rate = mpc_rate[st->codec->extradata[2] & 3];
     av_set_pts_info(st, 32, MPC_FRAMESIZE, st->codec->sample_rate);
     /* scan for seekpoints */
-    s->start_time = 0;
-    s->duration = (int64_t)c->fcount * MPC_FRAMESIZE * AV_TIME_BASE / st->codec->sample_rate;
+    st->start_time = 0;
+    st->duration = c->fcount;
 
     /* try to read APE tags */
     if (!url_is_streamed(s->pb)) {
@@ -164,6 +170,8 @@ static int mpc_read_packet(AVFormatContext *s, AVPacket *pkt)
 
     pkt->data[0] = curbits;
     pkt->data[1] = (c->curframe > c->fcount);
+    pkt->data[2] = 0;
+    pkt->data[3] = 0;
 
     pkt->stream_index = 0;
     pkt->pts = cur;