[FFmpeg-soc] [soc]: r2412 - dvbmuxer/mpegpesenc.c
bcoudurier
subversion at mplayerhq.hu
Mon Jun 9 03:07:41 CEST 2008
Author: bcoudurier
Date: Mon Jun 9 03:07:41 2008
New Revision: 2412
Log:
reexpand to minimize svn diff
Modified:
dvbmuxer/mpegpesenc.c
Modified: dvbmuxer/mpegpesenc.c
==============================================================================
--- dvbmuxer/mpegpesenc.c (original)
+++ dvbmuxer/mpegpesenc.c Mon Jun 9 03:07:41 2008
@@ -87,37 +87,43 @@ static int get_nb_frames(AVFormatContext
return nb_frames;
}
-static void calc_pes_header(StreamInfo *stream,
- int *packet_size, int *header_len, int64_t *pts, int64_t *dts,
- int *payload_size, int *startcode, int *stuffing_size,
- int *trailer_size, int *pad_packet_bytes)
+int ff_pes_write_buf(AVFormatContext *ctx, int stream_index, uint8_t *buf,
+ int64_t *pts, int64_t *dts,
+ int trailer_size, int *packet_size, int *pad_packet_bytes,
+ int *payload_size, int *stuffing_size)
{
+ StreamInfo *stream = ctx->streams[stream_index]->priv_data;
+ int startcode, i, header_len;
+ int pes_flags = 0;
+ uint8_t *p = buf;
+ int nb_frames;
+
/* packet header size */
*packet_size -= 6;
/* packet header */
if (stream->format & PES_FMT_MPEG2) {
- *header_len = 3;
- if (stream->packet_number==0 && stream->format != PES_FMT_TS)
- *header_len += 3; /* PES extension */
- *header_len += 1; /* obligatory stuffing byte */
+ header_len = 3;
+ if (stream->packet_number==0)
+ header_len += 3; /* PES extension */
+ header_len += 1; /* obligatory stuffing byte */
} else {
- *header_len = 0;
+ header_len = 0;
}
if (*pts != AV_NOPTS_VALUE) {
if (*dts != *pts)
- *header_len += 5 + 5;
+ header_len += 5 + 5;
else
- *header_len += 5;
+ header_len += 5;
} else {
if (!(stream->format & PES_FMT_MPEG2))
- (*header_len)++;
+ header_len++;
}
- *payload_size = *packet_size - *header_len;
+ *payload_size = *packet_size - header_len;
if (stream->id < 0xc0) {
- *startcode = PRIVATE_STREAM_1;
+ startcode = PRIVATE_STREAM_1;
*payload_size -= 1;
if (stream->id >= 0x40) {
*payload_size -= 3;
@@ -125,20 +131,20 @@ static void calc_pes_header(StreamInfo *
*payload_size -= 3;
}
} else {
- *startcode = 0x100 + stream->id;
+ startcode = 0x100 + stream->id;
}
*stuffing_size = *payload_size - av_fifo_size(&stream->fifo);
// first byte does not fit -> reset pts/dts + stuffing
- if(*payload_size <= *trailer_size && *pts != AV_NOPTS_VALUE){
+ if(*payload_size <= trailer_size && *pts != AV_NOPTS_VALUE){
int timestamp_len=0;
if(*dts != *pts)
timestamp_len += 5;
if(*pts != AV_NOPTS_VALUE)
timestamp_len += stream->format & PES_FMT_MPEG2 ? 5 : 4;
*pts=*dts= AV_NOPTS_VALUE;
- *header_len -= timestamp_len;
+ header_len -= timestamp_len;
if (stream->format == PES_FMT_DVD && stream->align_iframe) {
*pad_packet_bytes += timestamp_len;
*packet_size -= timestamp_len;
@@ -146,8 +152,8 @@ static void calc_pes_header(StreamInfo *
*payload_size += timestamp_len;
}
*stuffing_size += timestamp_len;
- if(*payload_size > *trailer_size)
- *stuffing_size += *payload_size - *trailer_size;
+ if(*payload_size > trailer_size)
+ *stuffing_size += *payload_size - trailer_size;
}
if (stream->format != PES_FMT_TS) {
@@ -171,22 +177,6 @@ static void calc_pes_header(StreamInfo *
*payload_size -= *stuffing_size;
*stuffing_size = 0;
}
-}
-
-int ff_pes_write_buf(AVFormatContext *ctx, int stream_index, uint8_t *buf,
- int64_t *pts, int64_t *dts,
- int trailer_size, int *packet_size, int *pad_packet_bytes,
- int *payload_size, int *stuffing_size)
-{
- StreamInfo *stream = ctx->streams[stream_index]->priv_data;
- int startcode, i, header_len;
- int pes_flags = 0;
- uint8_t *p = buf;
- int nb_frames;
-
- calc_pes_header(stream, packet_size, &header_len, pts, dts,
- payload_size, &startcode, stuffing_size,
- &trailer_size, pad_packet_bytes);
nb_frames= get_nb_frames(ctx, stream, *payload_size - *stuffing_size);
@@ -307,11 +297,59 @@ int ff_pes_remove_decoded_packets(AVForm
return 0;
}
-static int find_beststream(AVFormatContext *ctx, int packet_size, int flush, int64_t *scr, int *best_i)
+void ff_pes_write_packet(AVFormatContext *ctx, AVPacket *pkt, int packet_number)
{
- int i, avail_space;
+ int stream_index= pkt->stream_index;
+ int size= pkt->size;
+ uint8_t *buf= pkt->data;
+ AVStream *st= ctx->streams[stream_index];
+ StreamInfo *stream= st->priv_data;
+ int64_t pts, dts;
+ PacketDesc *pkt_desc;
+ const int preload= av_rescale(ctx->preload, 90000, AV_TIME_BASE);
+ const int is_iframe = st->codec->codec_type == CODEC_TYPE_VIDEO && (pkt->flags & PKT_FLAG_KEY);
+
+ pts= pkt->pts;
+ dts= pkt->dts;
+
+ if(pts != AV_NOPTS_VALUE) pts += preload;
+ if(dts != AV_NOPTS_VALUE) dts += preload;
+
+//av_log(ctx, AV_LOG_DEBUG, "dts:%f pts:%f flags:%d stream:%d nopts:%d\n", dts/90000.0, pts/90000.0, pkt->flags, pkt->stream_index, pts != AV_NOPTS_VALUE);
+ if (!stream->premux_packet)
+ stream->next_packet = &stream->premux_packet;
+ *stream->next_packet=
+ pkt_desc= av_mallocz(sizeof(PacketDesc));
+ pkt_desc->pts= pts;
+ pkt_desc->dts= dts;
+ pkt_desc->unwritten_size=
+ pkt_desc->size= size;
+ if(!stream->predecode_packet)
+ stream->predecode_packet= pkt_desc;
+ stream->next_packet= &pkt_desc->next;
+
+ av_fifo_realloc(&stream->fifo, av_fifo_size(&stream->fifo) + size);
+
+ if (stream->format == PES_FMT_DVD){
+ if (is_iframe && (packet_number == 0 || (pts - stream->vobu_start_pts >= 36000))) { // min VOBU length 0.4 seconds (mpucoder)
+ stream->bytes_to_iframe = av_fifo_size(&stream->fifo);
+ stream->align_iframe = 1;
+ stream->vobu_start_pts = pts;
+ }
+ }
+
+ av_fifo_generic_write(&stream->fifo, buf, size, NULL);
+}
+
+int ff_pes_output_packet(AVFormatContext *ctx, int packet_size, int64_t *cr,
+ int *best_i, int flush, int (*flush_packet)())
+{
+ AVStream *st;
+ StreamInfo *stream;
+ int i, avail_space=0, trailer_size;
int best_score= INT_MIN;
int ignore_constraints=0;
+ PacketDesc *timestamp_packet;
const int64_t max_delay= av_rescale(ctx->max_delay, 90000, AV_TIME_BASE);
retry:
@@ -335,7 +373,7 @@ retry:
if(space < packet_size && !ignore_constraints)
continue;
- if(next_pkt && next_pkt->dts - *scr > max_delay)
+ if(next_pkt && next_pkt->dts - *cr > max_delay)
continue;
if(rel_space > best_score){
@@ -357,80 +395,22 @@ retry:
}
#if 0
- av_log(ctx, AV_LOG_DEBUG, "bumping scr, scr:%f, dts:%f\n",
- scr/90000.0, best_dts/90000.0);
+ av_log(ctx, AV_LOG_DEBUG, "bumping cr, cr:%f, dts:%f\n",
+ cr/90000.0, best_dts/90000.0);
#endif
if(best_dts == INT64_MAX)
return 0;
- if(*scr >= best_dts+1 && !ignore_constraints){
+ if(*cr >= best_dts+1 && !ignore_constraints){
av_log(ctx, AV_LOG_ERROR, "packet too large, ignoring buffer limits to mux it\n");
ignore_constraints= 1;
}
- *scr= FFMAX(best_dts+1, *scr);
- if(ff_pes_remove_decoded_packets(ctx, *scr) < 0)
+ *cr= FFMAX(best_dts+1, *cr);
+ if(ff_pes_remove_decoded_packets(ctx, *cr) < 0)
return -1;
goto retry;
}
- assert(avail_space >= packet_size || ignore_constraints);
- return 1;
-}
-
-void ff_pes_write_packet(AVFormatContext *ctx, AVPacket *pkt, int packet_number)
-{
- int stream_index= pkt->stream_index;
- int size= pkt->size;
- uint8_t *buf= pkt->data;
- AVStream *st= ctx->streams[stream_index];
- StreamInfo *stream= st->priv_data;
- int64_t pts, dts;
- PacketDesc *pkt_desc;
- const int preload= av_rescale(ctx->preload, 90000, AV_TIME_BASE);
- const int is_iframe = st->codec->codec_type == CODEC_TYPE_VIDEO && (pkt->flags & PKT_FLAG_KEY);
-
- pts= pkt->pts;
- dts= pkt->dts;
-
- if(pts != AV_NOPTS_VALUE) pts += preload;
- if(dts != AV_NOPTS_VALUE) dts += preload;
-
-//av_log(ctx, AV_LOG_DEBUG, "dts:%f pts:%f flags:%d stream:%d nopts:%d\n", dts/90000.0, pts/90000.0, pkt->flags, pkt->stream_index, pts != AV_NOPTS_VALUE);
- if (!stream->premux_packet)
- stream->next_packet = &stream->premux_packet;
- *stream->next_packet=
- pkt_desc= av_mallocz(sizeof(PacketDesc));
- pkt_desc->pts= pts;
- pkt_desc->dts= dts;
- pkt_desc->unwritten_size=
- pkt_desc->size= size;
- if(!stream->predecode_packet)
- stream->predecode_packet= pkt_desc;
- stream->next_packet= &pkt_desc->next;
-
- av_fifo_realloc(&stream->fifo, av_fifo_size(&stream->fifo) + size);
-
- if (stream->format == PES_FMT_DVD){
- if (is_iframe && (packet_number == 0 || (pts - stream->vobu_start_pts >= 36000))) { // min VOBU length 0.4 seconds (mpucoder)
- stream->bytes_to_iframe = av_fifo_size(&stream->fifo);
- stream->align_iframe = 1;
- stream->vobu_start_pts = pts;
- }
- }
-
- av_fifo_generic_write(&stream->fifo, buf, size, NULL);
-}
-int ff_pes_output_packet(AVFormatContext *ctx, int packet_size, int64_t *cr,
- int *best_i, int flush, int (*flush_packet)())
-{
- AVStream *st;
- StreamInfo *stream;
- int trailer_size, res;
- PacketDesc *timestamp_packet;
-
- if((res = find_beststream(ctx, packet_size,
- flush, cr, best_i)) <= 0)
- return res;
assert(*best_i >= 0);
st = ctx->streams[*best_i];
@@ -438,6 +418,8 @@ int ff_pes_output_packet(AVFormatContext
assert(av_fifo_size(&stream->fifo) > 0);
+ assert(avail_space >= packet_size || ignore_constraints);
+
timestamp_packet= stream->premux_packet;
if(timestamp_packet->unwritten_size == timestamp_packet->size){
trailer_size= 0;
More information about the FFmpeg-soc
mailing list