return av_probe_input_format2(pd, is_opened, &score);
}
+static int set_codec_from_probe_data(AVStream *st, AVProbeData *pd, int score)
+{
+ AVInputFormat *fmt;
+ fmt = av_probe_input_format2(pd, 1, &score);
+
+ if (fmt) {
+ if (strncmp(fmt->name, "mp3", 3) == 0)
+ st->codec->codec_id = CODEC_ID_MP3;
+ else if (strncmp(fmt->name, "ac3", 3) == 0)
+ 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;
+}
+
/************************************************************/
/* input media file */
/*******************************************************/
+static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt){
+ AVPacketList *pktl;
+ AVPacketList **plast_pktl= packet_buffer;
+
+ while(*plast_pktl) plast_pktl= &(*plast_pktl)->next; //FIXME maybe maintain pointer to the last?
+
+ pktl = av_mallocz(sizeof(AVPacketList));
+ if (!pktl)
+ return NULL;
+
+ /* add the packet in the buffered packet list */
+ *plast_pktl = pktl;
+ pktl->pkt= *pkt;
+ return &pktl->pkt;
+}
+
int av_read_packet(AVFormatContext *s, AVPacket *pkt)
{
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];
+
+ if(!pktl && st->codec->codec_id!=CODEC_ID_PROBE)
+ return ret;
+
+ add_to_pktbuf(&s->raw_packet_buffer, pkt);
+
+ 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(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);
+ }
+ }
+ }
+ }
}
/**********************************************************/
if (st->last_IP_duration == 0)
st->last_IP_duration = pkt->duration;
if(pkt->dts != AV_NOPTS_VALUE)
- st->cur_dts = pkt->dts + st->last_IP_duration;
+ st->cur_dts = pkt->dts + st->last_IP_duration;
st->last_IP_duration = pkt->duration;
st->last_IP_pts= pkt->pts;
/* cannot compute PTS if not present (we can compute it only
pkt->pts = st->cur_dts;
pkt->dts = pkt->pts;
if(pkt->pts != AV_NOPTS_VALUE)
- st->cur_dts = pkt->pts + pkt->duration;
+ st->cur_dts = pkt->pts + pkt->duration;
}
}
return 0;
}
-static AVPacket *add_to_pktbuf(AVFormatContext *s, AVPacket *pkt){
- AVPacketList *pktl= s->packet_buffer;
- AVPacketList **plast_pktl= &s->packet_buffer;
-
- while(*plast_pktl) plast_pktl= &(*plast_pktl)->next; //FIXME maybe maintain pointer to the last?
-
- pktl = av_mallocz(sizeof(AVPacketList));
- if (!pktl)
- return NULL;
-
- /* add the packet in the buffered packet list */
- *plast_pktl = pktl;
- pktl->pkt= *pkt;
- return &pktl->pkt;
-}
-
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
{
AVPacketList *pktl;
return ret;
}
- if(av_dup_packet(add_to_pktbuf(s, pkt)) < 0)
+ if(av_dup_packet(add_to_pktbuf(&s->packet_buffer, pkt)) < 0)
return AVERROR(ENOMEM);
}else{
assert(!s->packet_buffer);
return ret;
}
-static int set_codec_from_probe_data(AVStream *st, AVProbeData *pd, int score)
-{
- AVInputFormat *fmt;
- fmt = av_probe_input_format2(pd, 1, &score);
-
- if (fmt) {
- if (strncmp(fmt->name, "mp3", 3) == 0)
- st->codec->codec_id = CODEC_ID_MP3;
- else if (strncmp(fmt->name, "ac3", 3) == 0)
- st->codec->codec_id = CODEC_ID_AC3;
- }
- return !!fmt;
-}
-
unsigned int codec_get_tag(const AVCodecTag *tags, int id)
{
while (tags->id != CODEC_ID_NONE) {
break;
}
- pkt= add_to_pktbuf(ic, &pkt1);
+ pkt= add_to_pktbuf(&ic->packet_buffer, &pkt1);
if(av_dup_packet(pkt) < 0)
return AVERROR(ENOMEM);