Merge commit '68b467742092364f9306283f40effde2c12efe08'
authorMichael Niedermayer <michaelni@gmx.at>
Tue, 17 Sep 2013 10:37:04 +0000 (12:37 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Tue, 17 Sep 2013 10:44:31 +0000 (12:44 +0200)
* commit '68b467742092364f9306283f40effde2c12efe08':
  lavf: Make probe_codec return an error code

Conflicts:
libavformat/utils.c

A failure to reallocate should not free the array as it is used
to probe the codec. And failure to reallocate if the following
probe succeeds isnt a fatal error for probe_codec(). Thus this
is only partially merged to ensure probing still is attempted
with the data available.

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavformat/utils.c

@@@ -564,27 -449,11 +564,27 @@@ fail
  
  /*******************************************************/
  
- static void probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt)
 +static void force_codec_ids(AVFormatContext *s, AVStream *st)
 +{
 +    switch(st->codec->codec_type){
 +    case AVMEDIA_TYPE_VIDEO:
 +        if(s->video_codec_id)   st->codec->codec_id= s->video_codec_id;
 +        break;
 +    case AVMEDIA_TYPE_AUDIO:
 +        if(s->audio_codec_id)   st->codec->codec_id= s->audio_codec_id;
 +        break;
 +    case AVMEDIA_TYPE_SUBTITLE:
 +        if(s->subtitle_codec_id)st->codec->codec_id= s->subtitle_codec_id;
 +        break;
 +    }
 +}
 +
+ static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt)
  {
 -    if(st->codec->codec_id == AV_CODEC_ID_PROBE){
 +    if(st->request_probe>0){
          AVProbeData *pd = &st->probe_data;
 -        av_log(s, AV_LOG_DEBUG, "probing stream %d\n", st->index);
 +        int end;
 +        av_log(s, AV_LOG_DEBUG, "probing stream %d pp:%d\n", st->index, st->probe_packets);
          --st->probe_packets;
  
          if (pkt) {
@@@ -604,24 -472,18 +604,25 @@@ no_packet
              }
          }
  
 -        if (!st->probe_packets ||
 -            av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)) {
 -            set_codec_from_probe_data(s, st, pd, st->probe_packets > 0 ? AVPROBE_SCORE_MAX/4 : 0);
 -            if(st->codec->codec_id != AV_CODEC_ID_PROBE){
 +        end=    s->raw_packet_buffer_remaining_size <= 0
 +                || st->probe_packets<=0;
 +
 +        if(end || av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)){
 +            int score= set_codec_from_probe_data(s, st, pd);
 +            if(    (st->codec->codec_id != AV_CODEC_ID_NONE && score > AVPROBE_SCORE_RETRY)
 +                || end){
                  pd->buf_size=0;
                  av_freep(&pd->buf);
 -                av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index);
 +                st->request_probe= -1;
 +                if(st->codec->codec_id != AV_CODEC_ID_NONE){
 +                    av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index);
 +                }else
 +                    av_log(s, AV_LOG_WARNING, "probed stream %d failed\n", st->index);
              }
 +            force_codec_ids(s, st);
          }
      }
+     return 0;
  }
  
  int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
          if (pktl) {
              *pkt = pktl->pkt;
              st = s->streams[pkt->stream_index];
-             if (s->raw_packet_buffer_remaining_size <= 0)
-                 probe_codec(s, st, NULL);
 -            if (st->codec->codec_id != AV_CODEC_ID_PROBE || !st->probe_packets ||
 -                s->raw_packet_buffer_remaining_size < pkt->size) {
 -                AVProbeData *pd;
 -                if (st->probe_packets) {
 -                    if ((err = probe_codec(s, st, NULL)) < 0)
 -                        return err;
 -                }
 -                pd = &st->probe_data;
 -                av_freep(&pd->buf);
 -                pd->buf_size = 0;
++            if (s->raw_packet_buffer_remaining_size <= 0) {
++                if ((err = probe_codec(s, st, NULL)) < 0)
++                    return err;
++            }
 +            if(st->request_probe <= 0){
                  s->raw_packet_buffer = pktl->next;
                  s->raw_packet_buffer_remaining_size += pkt->size;
                  av_free(pktl);
              for (i = 0; i < s->nb_streams; i++) {
                  st = s->streams[i];
                  if (st->probe_packets) {
-                     probe_codec(s, st, NULL);
+                     if ((err = probe_codec(s, st, NULL)) < 0)
+                         return err;
                  }
 +                av_assert0(st->request_probe <= 0);
              }
              continue;
          }