static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
AVCodecParserContext *pc, AVPacket *pkt)
{
- int num, den, presentation_delayed;
+ int num, den, presentation_delayed, delay;
/* handle wrapping */
if(st->cur_dts != AV_NOPTS_VALUE){
if(pkt->pts != AV_NOPTS_VALUE)
pkt->flags |= PKT_FLAG_KEY;
/* do we have a video B frame ? */
+ delay= st->codec->has_b_frames;
presentation_delayed = 0;
- if (st->codec->codec_type == CODEC_TYPE_VIDEO) {
/* XXX: need has_b_frame, but cannot get it if the codec is
not initialized */
- if (( st->codec->codec_id == CODEC_ID_H264
- || st->codec->has_b_frames) &&
+ if (delay &&
pc && pc->pict_type != FF_B_TYPE)
presentation_delayed = 1;
/* this may be redundant, but it shouldnt hurt */
if(pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts > pkt->dts)
presentation_delayed = 1;
- }
if(st->cur_dts == AV_NOPTS_VALUE){
- if(presentation_delayed) st->cur_dts = -pkt->duration;
- else st->cur_dts = 0;
+ st->cur_dts = -delay * pkt->duration;
}
// av_log(NULL, AV_LOG_DEBUG, "IN delayed:%d pts:%"PRId64", dts:%"PRId64" cur_dts:%"PRId64" st:%d pc:%p\n", presentation_delayed, pkt->pts, pkt->dts, st->cur_dts, pkt->stream_index, pc);
int duration_count[MAX_STREAMS]={0};
double (*duration_error)[MAX_STD_TIMEBASES];
offset_t old_offset = url_ftell(&ic->pb);
+ int64_t codec_info_duration[MAX_STREAMS]={0};
+ int codec_info_nb_frames[MAX_STREAMS]={0};
duration_error = av_mallocz(MAX_STREAMS * sizeof(*duration_error));
if (!duration_error) return AVERROR_NOMEM;
read_size += pkt->size;
st = ic->streams[pkt->stream_index];
- if(st->codec_info_nb_frames>1) //FIXME move codec_info_nb_frames and codec_info_duration from AVStream into this func
- st->codec_info_duration += pkt->duration;
+ if(codec_info_nb_frames[st->index]>1)
+ codec_info_duration[st->index] += pkt->duration;
if (pkt->duration != 0)
- st->codec_info_nb_frames++;
+ codec_info_nb_frames[st->index]++;
{
int index= pkt->stream_index;
duration_error[index][i] += error*error;
}
duration_count[index]++;
-
- if(st->codec_info_nb_frames == 0 && 0)
- st->codec_info_duration += duration;
}
if(last == AV_NOPTS_VALUE || duration_count[index]<=1)
last_dts[pkt->stream_index]= pkt->dts;
(st->codec->codec_id == CODEC_ID_MPEG4 && !st->need_parsing))*/)
try_decode_frame(st, pkt->data, pkt->size);
- if (av_rescale_q(st->codec_info_duration, st->time_base, AV_TIME_BASE_Q) >= ic->max_analyze_duration) {
+ if (av_rescale_q(codec_info_duration[st->index], st->time_base, AV_TIME_BASE_Q) >= ic->max_analyze_duration) {
break;
}
count++;
return -1;
}
-void av_hex_dump(FILE *f, uint8_t *buf, int size)
+static void hex_dump_internal(void *avcl, FILE *f, int level, uint8_t *buf, int size)
{
int len, i, j, c;
+#define PRINT(...) do { if (!f) av_log(avcl, level, __VA_ARGS__); else fprintf(f, __VA_ARGS__); } while(0)
for(i=0;i<size;i+=16) {
len = size - i;
if (len > 16)
len = 16;
- fprintf(f, "%08x ", i);
+ PRINT("%08x ", i);
for(j=0;j<16;j++) {
if (j < len)
- fprintf(f, " %02x", buf[i+j]);
+ PRINT(" %02x", buf[i+j]);
else
- fprintf(f, " ");
+ PRINT(" ");
}
- fprintf(f, " ");
+ PRINT(" ");
for(j=0;j<len;j++) {
c = buf[i+j];
if (c < ' ' || c > '~')
c = '.';
- fprintf(f, "%c", c);
+ PRINT("%c", c);
}
- fprintf(f, "\n");
+ PRINT("\n");
}
+#undef PRINT
+}
+
+void av_hex_dump(FILE *f, uint8_t *buf, int size)
+{
+ hex_dump_internal(NULL, f, 0, buf, size);
+}
+
+void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size)
+{
+ hex_dump_internal(avcl, NULL, level, buf, size);
}
//FIXME needs to know the time_base
-void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload)
+static void pkt_dump_internal(void *avcl, FILE *f, int level, AVPacket *pkt, int dump_payload)
{
- fprintf(f, "stream #%d:\n", pkt->stream_index);
- fprintf(f, " keyframe=%d\n", ((pkt->flags & PKT_FLAG_KEY) != 0));
- fprintf(f, " duration=%0.3f\n", (double)pkt->duration / AV_TIME_BASE);
+#define PRINT(...) do { if (!f) av_log(avcl, level, __VA_ARGS__); else fprintf(f, __VA_ARGS__); } while(0)
+ PRINT("stream #%d:\n", pkt->stream_index);
+ PRINT(" keyframe=%d\n", ((pkt->flags & PKT_FLAG_KEY) != 0));
+ PRINT(" duration=%0.3f\n", (double)pkt->duration / AV_TIME_BASE);
/* DTS is _always_ valid after av_read_frame() */
- fprintf(f, " dts=");
+ PRINT(" dts=");
if (pkt->dts == AV_NOPTS_VALUE)
- fprintf(f, "N/A");
+ PRINT("N/A");
else
- fprintf(f, "%0.3f", (double)pkt->dts / AV_TIME_BASE);
+ PRINT("%0.3f", (double)pkt->dts / AV_TIME_BASE);
/* PTS may be not known if B frames are present */
- fprintf(f, " pts=");
+ PRINT(" pts=");
if (pkt->pts == AV_NOPTS_VALUE)
- fprintf(f, "N/A");
+ PRINT("N/A");
else
- fprintf(f, "%0.3f", (double)pkt->pts / AV_TIME_BASE);
- fprintf(f, "\n");
- fprintf(f, " size=%d\n", pkt->size);
+ PRINT("%0.3f", (double)pkt->pts / AV_TIME_BASE);
+ PRINT("\n");
+ PRINT(" size=%d\n", pkt->size);
+#undef PRINT
if (dump_payload)
av_hex_dump(f, pkt->data, pkt->size);
}
+void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload)
+{
+ pkt_dump_internal(NULL, f, 0, pkt, dump_payload);
+}
+
+void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload)
+{
+ pkt_dump_internal(avcl, NULL, level, pkt, dump_payload);
+}
+
void url_split(char *proto, int proto_size,
char *authorization, int authorization_size,
char *hostname, int hostname_size,