[MPlayer-cvslog] r24870 - trunk/libmpdemux/demux_lavf.c

nicodvb subversion at mplayerhq.hu
Sat Oct 27 21:00:07 CEST 2007


Author: nicodvb
Date: Sat Oct 27 21:00:07 2007
New Revision: 24870

Log:
moved to a new function handle_stream() the code to parse the streams and assign the demuxer_streams

Modified:
   trunk/libmpdemux/demux_lavf.c

Modified: trunk/libmpdemux/demux_lavf.c
==============================================================================
--- trunk/libmpdemux/demux_lavf.c	(original)
+++ trunk/libmpdemux/demux_lavf.c	Sat Oct 27 21:00:07 2007
@@ -270,74 +270,13 @@ static void parse_cryptokey(AVFormatCont
         *key++ = (char2int(str[0]) << 4) | char2int(str[1]);
 }
 
-static demuxer_t* demux_open_lavf(demuxer_t *demuxer){
-    AVFormatContext *avfc;
-    AVFormatParameters ap;
-    const AVOption *opt;
+static void handle_stream(demuxer_t *demuxer, AVFormatContext *avfc, int i) {
     lavf_priv_t *priv= demuxer->priv;
-    int i,g;
-    char mp_filename[256]="mp:";
-
-    memset(&ap, 0, sizeof(AVFormatParameters));
-
-    stream_seek(demuxer->stream, 0);
-
-    register_protocol(&mp_protocol);
-
-    avfc = av_alloc_format_context();
-
-    if (opt_cryptokey)
-        parse_cryptokey(avfc, opt_cryptokey);
-    if (correct_pts)
-        avfc->flags |= AVFMT_FLAG_GENPTS;
-    if (index_mode == 0)
-        avfc->flags |= AVFMT_FLAG_IGNIDX;
-
-    ap.prealloced_context = 1;
-    if(opt_probesize) {
-        opt = av_set_int(avfc, "probesize", opt_probesize);
-        if(!opt) mp_msg(MSGT_HEADER,MSGL_ERR, "demux_lavf, couldn't set option probesize to %u\n", opt_probesize);
-    }
-    if(opt_analyzeduration) {
-        opt = av_set_int(avfc, "analyzeduration", opt_analyzeduration * AV_TIME_BASE);
-        if(!opt) mp_msg(MSGT_HEADER,MSGL_ERR, "demux_lavf, couldn't set option analyzeduration to %u\n", opt_analyzeduration);
-    }
-
-    if(demuxer->stream->url)
-        strncpy(mp_filename + 3, demuxer->stream->url, sizeof(mp_filename)-3);
-    else
-        strncpy(mp_filename + 3, "foobar.dummy", sizeof(mp_filename)-3);
-    
-    url_fopen(&priv->pb, mp_filename, URL_RDONLY);
-    
-    ((URLContext*)(priv->pb.opaque))->priv_data= demuxer->stream;
-        
-    if(av_open_input_stream(&avfc, &priv->pb, mp_filename, priv->avif, &ap)<0){
-        mp_msg(MSGT_HEADER,MSGL_ERR,"LAVF_header: av_open_input_stream() failed\n");
-        return NULL;
-    }
-
-    priv->avfc= avfc;
-
-    if(av_find_stream_info(avfc) < 0){
-        mp_msg(MSGT_HEADER,MSGL_ERR,"LAVF_header: av_find_stream_info() failed\n");
-        return NULL;
-    }
-
-    if(avfc->title    [0]) demux_info_add(demuxer, "name"     , avfc->title    );
-    if(avfc->author   [0]) demux_info_add(demuxer, "author"   , avfc->author   );
-    if(avfc->copyright[0]) demux_info_add(demuxer, "copyright", avfc->copyright);
-    if(avfc->comment  [0]) demux_info_add(demuxer, "comments" , avfc->comment  );
-    if(avfc->album    [0]) demux_info_add(demuxer, "album"    , avfc->album    );
-//    if(avfc->year        ) demux_info_add(demuxer, "year"     , avfc->year     );
-//    if(avfc->track       ) demux_info_add(demuxer, "track"    , avfc->track    );
-    if(avfc->genre    [0]) demux_info_add(demuxer, "genre"    , avfc->genre    );
-
-    for(i=0; i<avfc->nb_streams; i++){
-        AVStream *st= avfc->streams[i];
-        AVCodecContext *codec= st->codec;
+    AVStream *st= avfc->streams[i];
+    AVCodecContext *codec= st->codec;
+    int g;
 
-        switch(codec->codec_type){
+    switch(codec->codec_type){
         case CODEC_TYPE_AUDIO:{
             WAVEFORMATEX *wf= calloc(sizeof(WAVEFORMATEX) + codec->extradata_size, 1);
             sh_audio_t* sh_audio;
@@ -363,12 +302,8 @@ static demuxer_t* demux_open_lavf(demuxe
             wf->nBlockAlign= codec->block_align ? codec->block_align : 1;
             wf->wBitsPerSample= codec->bits_per_sample;
             wf->cbSize= codec->extradata_size;
-            if(codec->extradata_size){
-                memcpy(
-                    wf + 1, 
-                    codec->extradata,
-                    codec->extradata_size);
-            }
+            if(codec->extradata_size)
+                memcpy(wf + 1, codec->extradata, codec->extradata_size);
             sh_audio->wf= wf;
             sh_audio->audio.dwSampleSize= codec->block_align;
             if(codec->frame_size && codec->sample_rate){
@@ -381,40 +316,39 @@ static demuxer_t* demux_open_lavf(demuxe
             g= ff_gcd(sh_audio->audio.dwScale, sh_audio->audio.dwRate);
             sh_audio->audio.dwScale /= g;
             sh_audio->audio.dwRate  /= g;
-//            printf("sca:%d rat:%d fs:%d sr:%d ba:%d\n", sh_audio->audio.dwScale, sh_audio->audio.dwRate, codec->frame_size, codec->sample_rate, codec->block_align);
+//          printf("sca:%d rat:%d fs:%d sr:%d ba:%d\n", sh_audio->audio.dwScale, sh_audio->audio.dwRate, codec->frame_size, codec->sample_rate, codec->block_align);
             sh_audio->ds= demuxer->audio;
             sh_audio->format= codec->codec_tag;
             sh_audio->channels= codec->channels;
             sh_audio->samplerate= codec->sample_rate;
             sh_audio->i_bps= codec->bit_rate/8;
             switch (codec->codec_id) {
-              case CODEC_ID_PCM_S8:
-              case CODEC_ID_PCM_U8:
-                sh_audio->samplesize = 1;
-                break;
-              case CODEC_ID_PCM_S16LE:
-              case CODEC_ID_PCM_S16BE:
-              case CODEC_ID_PCM_U16LE:
-              case CODEC_ID_PCM_U16BE:
-                sh_audio->samplesize = 2;
-                break;
-              case CODEC_ID_PCM_ALAW:
-                sh_audio->format = 0x6;
-                break;
-              case CODEC_ID_PCM_MULAW:
-                sh_audio->format = 0x7;
-                break;
+                case CODEC_ID_PCM_S8:
+                case CODEC_ID_PCM_U8:
+                    sh_audio->samplesize = 1;
+                    break;
+                case CODEC_ID_PCM_S16LE:
+                case CODEC_ID_PCM_S16BE:
+                case CODEC_ID_PCM_U16LE:
+                case CODEC_ID_PCM_U16BE:
+                    sh_audio->samplesize = 2;
+                    break;
+                case CODEC_ID_PCM_ALAW:
+                    sh_audio->format = 0x6;
+                    break;
+                case CODEC_ID_PCM_MULAW:
+                    sh_audio->format = 0x7;
+                    break;
             }
-            if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_wave_header(sh_audio->wf, MSGL_V);
-	    if((audio_lang && st->language[0] && !strncmp(audio_lang, st->language, 3))
-	        || (demuxer->audio->id == i || demuxer->audio->id == -1)
-	    ) {
-	        demuxer->audio->id = i;
+            if(mp_msg_test(MSGT_HEADER,MSGL_V) ) print_wave_header(sh_audio->wf, MSGL_V);
+            if((audio_lang && st->language[0] && !strncmp(audio_lang, st->language, 3))
+                || (demuxer->audio->id == i || demuxer->audio->id == -1)) {
+                demuxer->audio->id = i;
                 demuxer->audio->sh= demuxer->a_streams[i];
-	    }
-            else
+            } else
                 st->discard= AVDISCARD_ALL;
-            break;}
+            break;
+        }
         case CODEC_TYPE_VIDEO:{
             sh_video_t* sh_video;
             BITMAPINFOHEADER *bih;
@@ -442,15 +376,15 @@ static demuxer_t* demux_open_lavf(demuxe
                 sh_video->video.dwRate= st->time_base.den;
                 sh_video->video.dwScale= st->time_base.num;
             } else {
-            sh_video->video.dwRate= codec->time_base.den;
-            sh_video->video.dwScale= codec->time_base.num;
+                sh_video->video.dwRate= codec->time_base.den;
+                sh_video->video.dwScale= codec->time_base.num;
             }
             sh_video->fps=av_q2d(st->r_frame_rate);
             sh_video->frametime=1/av_q2d(st->r_frame_rate);
-            sh_video->format = bih->biCompression;
-            sh_video->aspect=   codec->width * codec->sample_aspect_ratio.num 
-                              / (float)(codec->height * codec->sample_aspect_ratio.den);
-            sh_video->i_bps= codec->bit_rate/8;
+            sh_video->format=bih->biCompression;
+            sh_video->aspect=codec->width * codec->sample_aspect_ratio.num 
+                               / (float)(codec->height * codec->sample_aspect_ratio.den);
+            sh_video->i_bps=codec->bit_rate/8;
             mp_msg(MSGT_DEMUX,MSGL_DBG2,"aspect= %d*%d/(%d*%d)\n", 
                 codec->width, codec->sample_aspect_ratio.num,
                 codec->height, codec->sample_aspect_ratio.den);
@@ -459,18 +393,21 @@ static demuxer_t* demux_open_lavf(demuxe
             if(codec->extradata_size)
                 memcpy(sh_video->bih + 1, codec->extradata, codec->extradata_size);
             if( mp_msg_test(MSGT_HEADER,MSGL_V) ) print_video_header(sh_video->bih, MSGL_V);
-/*    short 	biPlanes;
-    int  	biXPelsPerMeter;
-    int  	biYPelsPerMeter;
-    int 	biClrUsed;
-    int 	biClrImportant;*/
+            /*
+                short biPlanes;
+                int  biXPelsPerMeter;
+                int  biYPelsPerMeter;
+                int biClrUsed;
+                int biClrImportant;
+            */
             if(demuxer->video->id != i && demuxer->video->id != -1)
                 st->discard= AVDISCARD_ALL;
             else{
                 demuxer->video->id = i;
                 demuxer->video->sh= demuxer->v_streams[i];
             }
-            break;}
+            break;
+        }
         case CODEC_TYPE_SUBTITLE:{
             sh_sub_t* sh_sub;
             if(priv->sub_streams >= MAX_S_STREAMS)
@@ -484,11 +421,78 @@ static demuxer_t* demux_open_lavf(demuxe
             priv->sstreams[priv->sub_streams] = i;
             sh_sub->type = 't';
             demuxer->sub->sh = demuxer->s_streams[priv->sub_streams++];
-            break;}
+            break;
+        }
         default:
             st->discard= AVDISCARD_ALL;
-        }
     }
+}
+
+static demuxer_t* demux_open_lavf(demuxer_t *demuxer){
+    AVFormatContext *avfc;
+    AVFormatParameters ap;
+    const AVOption *opt;
+    lavf_priv_t *priv= demuxer->priv;
+    int i,g;
+    char mp_filename[256]="mp:";
+
+    memset(&ap, 0, sizeof(AVFormatParameters));
+
+    stream_seek(demuxer->stream, 0);
+
+    register_protocol(&mp_protocol);
+
+    avfc = av_alloc_format_context();
+
+    if (opt_cryptokey)
+        parse_cryptokey(avfc, opt_cryptokey);
+    if (correct_pts)
+        avfc->flags |= AVFMT_FLAG_GENPTS;
+    if (index_mode == 0)
+        avfc->flags |= AVFMT_FLAG_IGNIDX;
+
+    ap.prealloced_context = 1;
+    if(opt_probesize) {
+        opt = av_set_int(avfc, "probesize", opt_probesize);
+        if(!opt) mp_msg(MSGT_HEADER,MSGL_ERR, "demux_lavf, couldn't set option probesize to %u\n", opt_probesize);
+    }
+    if(opt_analyzeduration) {
+        opt = av_set_int(avfc, "analyzeduration", opt_analyzeduration * AV_TIME_BASE);
+        if(!opt) mp_msg(MSGT_HEADER,MSGL_ERR, "demux_lavf, couldn't set option analyzeduration to %u\n", opt_analyzeduration);
+    }
+
+    if(demuxer->stream->url)
+        strncpy(mp_filename + 3, demuxer->stream->url, sizeof(mp_filename)-3);
+    else
+        strncpy(mp_filename + 3, "foobar.dummy", sizeof(mp_filename)-3);
+    
+    url_fopen(&priv->pb, mp_filename, URL_RDONLY);
+    
+    ((URLContext*)(priv->pb.opaque))->priv_data= demuxer->stream;
+        
+    if(av_open_input_stream(&avfc, &priv->pb, mp_filename, priv->avif, &ap)<0){
+        mp_msg(MSGT_HEADER,MSGL_ERR,"LAVF_header: av_open_input_stream() failed\n");
+        return NULL;
+    }
+
+    priv->avfc= avfc;
+
+    if(av_find_stream_info(avfc) < 0){
+        mp_msg(MSGT_HEADER,MSGL_ERR,"LAVF_header: av_find_stream_info() failed\n");
+        return NULL;
+    }
+
+    if(avfc->title    [0]) demux_info_add(demuxer, "name"     , avfc->title    );
+    if(avfc->author   [0]) demux_info_add(demuxer, "author"   , avfc->author   );
+    if(avfc->copyright[0]) demux_info_add(demuxer, "copyright", avfc->copyright);
+    if(avfc->comment  [0]) demux_info_add(demuxer, "comments" , avfc->comment  );
+    if(avfc->album    [0]) demux_info_add(demuxer, "album"    , avfc->album    );
+//    if(avfc->year        ) demux_info_add(demuxer, "year"     , avfc->year     );
+//    if(avfc->track       ) demux_info_add(demuxer, "track"    , avfc->track    );
+    if(avfc->genre    [0]) demux_info_add(demuxer, "genre"    , avfc->genre    );
+
+    for(i=0; i<avfc->nb_streams; i++)
+        handle_stream(demuxer, avfc, i);
     
     mp_msg(MSGT_HEADER,MSGL_V,"LAVF: %d audio and %d video streams found\n",priv->audio_streams,priv->video_streams);
     mp_msg(MSGT_HEADER,MSGL_V,"LAVF: build %d\n", LIBAVFORMAT_BUILD);



More information about the MPlayer-cvslog mailing list