fmt = av_probe_input_format2(pd, 1, &score);
if (fmt) {
- if (strncmp(fmt->name, "mp3", 3) == 0)
+ if (!strcmp(fmt->name, "mp3"))
st->codec->codec_id = CODEC_ID_MP3;
- else if (strncmp(fmt->name, "ac3", 3) == 0)
+ else if (!strcmp(fmt->name, "ac3"))
st->codec->codec_id = CODEC_ID_AC3;
+ else if (!strcmp(fmt->name, "mpegvideo"))
+ st->codec->codec_id = CODEC_ID_MPEG2VIDEO;
+ else if (!strcmp(fmt->name, "h264"))
+ st->codec->codec_id = CODEC_ID_H264;
}
return !!fmt;
}
{
int ret;
AVStream *st;
- av_init_packet(pkt);
- ret= s->iformat->read_packet(s, pkt);
- if (ret < 0)
- return ret;
- st= s->streams[pkt->stream_index];
- switch(st->codec->codec_type){
- case CODEC_TYPE_VIDEO:
- if(s->video_codec_id) st->codec->codec_id= s->video_codec_id;
- break;
- case CODEC_TYPE_AUDIO:
- if(s->audio_codec_id) st->codec->codec_id= s->audio_codec_id;
- break;
- case CODEC_TYPE_SUBTITLE:
- if(s->subtitle_codec_id)st->codec->codec_id= s->subtitle_codec_id;
- break;
- }
+ for(;;){
+ AVPacketList *pktl = s->raw_packet_buffer;
- return ret;
+ if (pktl) {
+ *pkt = pktl->pkt;
+ if(s->streams[pkt->stream_index]->codec->codec_id != CODEC_ID_PROBE){
+ s->raw_packet_buffer = pktl->next;
+ av_free(pktl);
+ return 0;
+ }
+ }
+
+ av_init_packet(pkt);
+ ret= s->iformat->read_packet(s, pkt);
+ if (ret < 0)
+ return ret;
+ st= s->streams[pkt->stream_index];
+
+ switch(st->codec->codec_type){
+ case CODEC_TYPE_VIDEO:
+ if(s->video_codec_id) st->codec->codec_id= s->video_codec_id;
+ break;
+ case CODEC_TYPE_AUDIO:
+ if(s->audio_codec_id) st->codec->codec_id= s->audio_codec_id;
+ break;
+ case CODEC_TYPE_SUBTITLE:
+ if(s->subtitle_codec_id)st->codec->codec_id= s->subtitle_codec_id;
+ break;
+ }
+
+ if(!pktl && st->codec->codec_id!=CODEC_ID_PROBE)
+ return ret;
+
+ add_to_pktbuf(&s->raw_packet_buffer, pkt);
+
+ if(st->codec->codec_id == CODEC_ID_PROBE){
+ AVProbeData *pd = &st->probe_data;
+
+ pd->buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE);
+ memcpy(pd->buf+pd->buf_size, pkt->data, pkt->size);
+ pd->buf_size += pkt->size;
+ memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE);
+
+ if(av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)){
+ set_codec_from_probe_data(st, pd, 1);
+ if(st->codec->codec_id != CODEC_ID_PROBE){
+ pd->buf_size=0;
+ av_freep(&pd->buf);
+ }
+ }
+ }
+ }
}
/**********************************************************/
static int av_seek_frame_generic(AVFormatContext *s,
int stream_index, int64_t timestamp, int flags)
{
- int index;
+ int index, ret;
AVStream *st;
AVIndexEntry *ie;
if(st->nb_index_entries){
assert(st->index_entries);
ie= &st->index_entries[st->nb_index_entries-1];
- url_fseek(s->pb, ie->pos, SEEK_SET);
+ if ((ret = url_fseek(s->pb, ie->pos, SEEK_SET)) < 0)
+ return ret;
av_update_cur_dts(s, st, ie->timestamp);
- }else
- url_fseek(s->pb, 0, SEEK_SET);
-
+ }else{
+ if ((ret = url_fseek(s->pb, 0, SEEK_SET)) < 0)
+ return ret;
+ }
for(i=0;; i++) {
int ret = av_read_frame(s, &pkt);
if(ret<0)
return 0;
}
ie = &st->index_entries[index];
- url_fseek(s->pb, ie->pos, SEEK_SET);
-
+ if ((ret = url_fseek(s->pb, ie->pos, SEEK_SET)) < 0)
+ return ret;
av_update_cur_dts(s, st, ie->timestamp);
return 0;
offset_t old_offset = url_ftell(ic->pb);
int64_t codec_info_duration[MAX_STREAMS]={0};
int codec_info_nb_frames[MAX_STREAMS]={0};
- AVProbeData probe_data[MAX_STREAMS];
- int codec_identified[MAX_STREAMS]={0};
duration_error = av_mallocz(MAX_STREAMS * sizeof(*duration_error));
if (!duration_error) return AVERROR(ENOMEM);
last_dts[i]= AV_NOPTS_VALUE;
}
- memset(probe_data, 0, sizeof(probe_data));
count = 0;
read_size = 0;
for(;;) {
}
pkt= add_to_pktbuf(&ic->packet_buffer, &pkt1);
- if(av_dup_packet(pkt) < 0)
+ if(av_dup_packet(pkt) < 0) {
+ av_free(duration_error);
return AVERROR(ENOMEM);
+ }
read_size += pkt->size;
}
if(last == AV_NOPTS_VALUE || duration_count[index]<=1)
last_dts[pkt->stream_index]= pkt->dts;
-
- if (st->codec->codec_id == CODEC_ID_NONE) {
- AVProbeData *pd = &(probe_data[st->index]);
- pd->buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE);
- memcpy(pd->buf+pd->buf_size, pkt->data, pkt->size);
- pd->buf_size += pkt->size;
- memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE);
- }
}
if(st->parser && st->parser->parser->split && !st->codec->extradata){
int i= st->parser->parser->split(st->codec, pkt->data, pkt->size);
}
}
}else if(st->codec->codec_type == CODEC_TYPE_AUDIO) {
- if (st->codec->codec_id == CODEC_ID_NONE && probe_data[st->index].buf_size > 0) {
- codec_identified[st->index] = set_codec_from_probe_data(st, &(probe_data[st->index]), 1);
- if (codec_identified[st->index]) {
- st->need_parsing = AVSTREAM_PARSE_FULL;
- }
- }
if(!st->codec->bits_per_sample)
st->codec->bits_per_sample= av_get_bits_per_sample(st->codec->codec_id);
}
av_estimate_timings(ic, old_offset);
- for(i=0;i<ic->nb_streams;i++) {
- st = ic->streams[i];
- if (codec_identified[st->index])
- break;
- }
- //FIXME this is a mess
- if(i!=ic->nb_streams){
- av_read_frame_flush(ic);
- for(i=0;i<ic->nb_streams;i++) {
- st = ic->streams[i];
- if (codec_identified[st->index]) {
- av_seek_frame(ic, st->index, 0.0, 0);
- }
- st->cur_dts= st->first_dts;
- }
- url_fseek(ic->pb, ic->data_offset, SEEK_SET);
- }
-
compute_chapters_end(ic);
#if 0
#endif
av_free(duration_error);
- for(i=0;i<MAX_STREAMS;i++){
- av_freep(&(probe_data[i].buf));
- }
return ret;
}
void av_set_pts_info(AVStream *s, int pts_wrap_bits,
int pts_num, int pts_den)
{
+ unsigned int gcd= ff_gcd(pts_num, pts_den);
s->pts_wrap_bits = pts_wrap_bits;
- s->time_base.num = pts_num;
- s->time_base.den = pts_den;
+ s->time_base.num = pts_num/gcd;
+ s->time_base.den = pts_den/gcd;
+
+ if(gcd>1)
+ av_log(NULL, AV_LOG_DEBUG, "st:%d removing common factor %d from timebase\n", s->index, gcd);
}
/* fraction handling */