On Mon, Mar 17, 2014 at 7:03 PM, Keiji Costantini <[email protected]> wrote:
> ---
> libavformat/mpegts.c | 489
> +++++++++++++++++++++++++++++----------------------
> 1 file changed, 278 insertions(+), 211 deletions(-)
>
> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
> index 5a3561f..63778a7 100644
> --- a/libavformat/mpegts.c
> +++ b/libavformat/mpegts.c
> @@ -37,18 +37,18 @@
> #include "isom.h"
>
> /* maximum size in which we look for synchronisation if
> - synchronisation is lost */
> + * synchronisation is lost */
> #define MAX_RESYNC_SIZE 65536
>
> -#define MAX_PES_PAYLOAD 200*1024
> +#define MAX_PES_PAYLOAD 200 * 1024
>
> #define MAX_MP4_DESCR_COUNT 16
>
> -#define MOD_UNLIKELY(modulus, dividend, divisor, prev_dividend) \
> - do { \
> +#define MOD_UNLIKELY(modulus, dividend, divisor, prev_dividend)
> \
> + do {
> \
> if ((prev_dividend) == 0 || (dividend) - (prev_dividend) !=
> (divisor)) \
> - (modulus) = (dividend) % (divisor); \
> - (prev_dividend) = (dividend); \
> + (modulus) = (dividend) % (divisor);
> \
> + (prev_dividend) = (dividend);
> \
> } while (0)
>
> enum MpegTSFilterType {
> @@ -58,23 +58,24 @@ enum MpegTSFilterType {
>
> typedef struct MpegTSFilter MpegTSFilter;
>
> -typedef int PESCallback(MpegTSFilter *f, const uint8_t *buf, int len, int
> is_start, int64_t pos);
> +typedef int PESCallback (MpegTSFilter * f, const uint8_t * buf, int len,
> + int is_start, int64_t pos);
this should be *f, *buf
>
> typedef struct MpegTSPESFilter {
> PESCallback *pes_cb;
> void *opaque;
> } MpegTSPESFilter;
>
> -typedef void SectionCallback(MpegTSFilter *f, const uint8_t *buf, int len);
> +typedef void SectionCallback (MpegTSFilter * f, const uint8_t * buf, int
> len);
same
>
> -typedef void SetServiceCallback(void *opaque, int ret);
> +typedef void SetServiceCallback (void *opaque, int ret);
>
> typedef struct MpegTSSectionFilter {
> int section_index;
> int section_h_size;
> uint8_t *section_buf;
> - unsigned int check_crc:1;
> - unsigned int end_of_section_reached:1;
> + unsigned int check_crc : 1;
> + unsigned int end_of_section_reached : 1;
> SectionCallback *section_cb;
> void *opaque;
> } MpegTSSectionFilter;
> @@ -261,15 +265,15 @@ static int discard_pid(MpegTSContext *ts, unsigned int
> pid)
> if (k == ts->stream->nb_programs)
> return 0;
>
> - for(i=0; i<ts->nb_prg; i++) {
> + for (i = 0; i < ts->nb_prg; i++) {
> p = &ts->prg[i];
> - for(j=0; j<p->nb_pids; j++) {
> - if(p->pids[j] != pid)
> + for (j = 0; j < p->nb_pids; j++) {
> + if (p->pids[j] != pid)
> continue;
> //is program with id p->id set to be discarded?
space should be added after //
(here and elsewhere)
> - for(k=0; k<ts->stream->nb_programs; k++) {
> - if(ts->stream->programs[k]->id == p->id) {
> - if(ts->stream->programs[k]->discard == AVDISCARD_ALL)
> + for (k = 0; k < ts->stream->nb_programs; k++) {
> + if (ts->stream->programs[k]->id == p->id) {
> + if (ts->stream->programs[k]->discard == AVDISCARD_ALL)
> discarded++;
> else
> used++;
> @@ -399,25 +405,28 @@ static void mpegts_close_filter(MpegTSContext *ts,
> MpegTSFilter *filter)
> ts->pids[pid] = NULL;
> }
>
> -static int analyze(const uint8_t *buf, int size, int packet_size, int
> *index){
> +static int analyze(const uint8_t *buf, int size, int packet_size, int *index)
> +{
> int stat[TS_MAX_PACKET_SIZE];
> int i;
> int x=0;
> int best_score=0;
these should be spaced
>
> - memset(stat, 0, packet_size*sizeof(int));
> + memset(stat, 0, packet_size * sizeof(int));
>
> - for(x=i=0; i<size-3; i++){
> - if(buf[i] == 0x47 && !(buf[i+1] & 0x80) && (buf[i+3] & 0x30)){
> + for (x = i = 0; i < size - 3; i++) {
> + if (buf[i] == 0x47 && !(buf[i + 1] & 0x80) && (buf[i + 3] & 0x30)) {
> stat[x]++;
> - if(stat[x] > best_score){
> - best_score= stat[x];
> - if(index) *index= x;
> + if (stat[x] > best_score) {
> + best_score = stat[x];
> + if (index)
> + *index = x;
> }
> }
>
> x++;
> - if(x == packet_size) x= 0;y
> + if (x == packet_size)
> + x = 0;
> }
>
> return best_score;
> @@ -431,16 +440,20 @@ static int get_packet_size(const uint8_t *buf, int size)
> if (size < (TS_FEC_PACKET_SIZE * 5 + 1))
> return -1;
>
> - score = analyze(buf, size, TS_PACKET_SIZE, NULL);
> - dvhs_score = analyze(buf, size, TS_DVHS_PACKET_SIZE, NULL);
> - fec_score= analyze(buf, size, TS_FEC_PACKET_SIZE, NULL);
> + score = analyze(buf, size, TS_PACKET_SIZE, NULL);
> + dvhs_score = analyze(buf, size, TS_DVHS_PACKET_SIZE, NULL);
> + fec_score = analyze(buf, size, TS_FEC_PACKET_SIZE, NULL);
> av_dlog(NULL, "score: %d, dvhs_score: %d, fec_score: %d \n",
> score, dvhs_score, fec_score);
>
> - if (score > fec_score && score > dvhs_score) return TS_PACKET_SIZE;
> - else if(dvhs_score > score && dvhs_score > fec_score) return
> TS_DVHS_PACKET_SIZE;
> - else if(score < fec_score && dvhs_score < fec_score) return
> TS_FEC_PACKET_SIZE;
> - else return -1;
> + if (score > fec_score && score > dvhs_score)
> + return TS_PACKET_SIZE;
> + else if (dvhs_score > score && dvhs_score > fec_score)
> + return TS_DVHS_PACKET_SIZE;
> + else if (score < fec_score && dvhs_score < fec_score)
> + return TS_FEC_PACKET_SIZE;
> + else
> + return -1;
> }
>
> typedef struct SectionHeader {
> @@ -553,21 +566,21 @@ static const StreamType ISO_types[] = {
> };
>
> static const StreamType HDMV_types[] = {
> - { 0x80, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_PCM_BLURAY },
> - { 0x81, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AC3 },
> - { 0x82, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS },
> - { 0x83, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_TRUEHD },
> - { 0x84, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_EAC3 },
> - { 0x85, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS }, /* DTS HD */
> - { 0x86, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS }, /* DTS HD MASTER*/
> - { 0x90, AVMEDIA_TYPE_SUBTITLE, AV_CODEC_ID_HDMV_PGS_SUBTITLE },
> + { 0x80, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_PCM_BLURAY },
> + { 0x81, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AC3 },
> + { 0x82, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS },
> + { 0x83, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_TRUEHD },
> + { 0x84, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_EAC3 },
> + { 0x85, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS }, /*
> DTS HD */
> + { 0x86, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS }, /*
> DTS HD MASTER*/
> + { 0x90, AVMEDIA_TYPE_SUBTITLE, AV_CODEC_ID_HDMV_PGS_SUBTITLE },
indentation should be on the left, not on the right
> { 0 },
> };
>
> /* ATSC ? */
> static const StreamType MISC_types[] = {
> - { 0x81, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AC3 },
> - { 0x8a, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS },
> + { 0x81, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AC3 },
> + { 0x8a, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS },
> { 0 },
> };
>
> @@ -594,7 +607,8 @@ static const StreamType DESC_types[] = {
> };
>
> static void mpegts_find_stream_type(AVStream *st,
> - uint32_t stream_type, const StreamType
> *types)
> + uint32_t stream_type,
> + const StreamType *types)
> {
> for (; types->stream_type; types++) {
> if (stream_type == types->stream_type) {
> @@ -609,16 +623,16 @@ static int mpegts_set_stream_info(AVStream *st,
> PESContext *pes,
> uint32_t stream_type, uint32_t
> prog_reg_desc)
> {
> avpriv_set_pts_info(st, 33, 1, 90000);
> - st->priv_data = pes;
> + st->priv_data = pes;
> st->codec->codec_type = AVMEDIA_TYPE_DATA;
> st->codec->codec_id = AV_CODEC_ID_NONE;
> - st->need_parsing = AVSTREAM_PARSE_FULL;
> - pes->st = st;
> - pes->stream_type = stream_type;
> + st->need_parsing = AVSTREAM_PARSE_FULL;
> + pes->st = st;
> + pes->stream_type = stream_type;
>
> av_log(pes->stream, AV_LOG_DEBUG,
> "stream=%d stream_type=%x pid=%x prog_reg_desc=%.4s\n",
> - st->index, pes->stream_type, pes->pid, (char*)&prog_reg_desc);
> + st->index, pes->stream_type, pes->pid, (char *)&prog_reg_desc);
>
> st->codec->codec_tag = pes->stream_type;
>
> @@ -644,11 +658,11 @@ static int mpegts_set_stream_info(AVStream *st,
> PESContext *pes,
>
> sub_st->id = pes->pid;
> avpriv_set_pts_info(sub_st, 33, 1, 90000);
> - sub_st->priv_data = sub_pes;
> + sub_st->priv_data = sub_pes;
> sub_st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
> sub_st->codec->codec_id = AV_CODEC_ID_AC3;
> - sub_st->need_parsing = AVSTREAM_PARSE_FULL;
> - sub_pes->sub_st = pes->sub_st = sub_st;
> + sub_st->need_parsing = AVSTREAM_PARSE_FULL;
> + sub_pes->sub_st = pes->sub_st = sub_st;
> }
> }
> if (st->codec->codec_id == AV_CODEC_ID_NONE)
> @@ -665,12 +679,13 @@ static void new_pes_packet(PESContext *pes, AVPacket
> *pkt)
> pkt->data = pes->buffer->data;
> pkt->size = pes->data_index;
>
> - if(pes->total_size != MAX_PES_PAYLOAD &&
> - pes->pes_header_size + pes->data_index != pes->total_size +
> PES_START_SIZE) {
> + if (pes->total_size != MAX_PES_PAYLOAD &&
> + pes->pes_header_size + pes->data_index != pes->total_size +
> + PES_START_SIZE) {
> av_log(pes->stream, AV_LOG_WARNING, "PES packet size mismatch\n");
> pes->flags |= AV_PKT_FLAG_CORRUPT;
> }
> - memset(pkt->data+pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
> + memset(pkt->data + pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
>
> // Separate out the AC3 substream from an HDMV combined TrueHD/AC3 PID
> if (pes->sub_st && pes->stream_type == 0x83 && pes->extended_stream_id
> == 0x76)
> @@ -691,14 +706,15 @@ static void new_pes_packet(PESContext *pes, AVPacket
> *pkt)
> pes->flags = 0;
> }
>
> -static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t
> *buf, int buf_size)
> +static int read_sl_header(PESContext *pes, SLConfigDescr *sl,
> + const uint8_t *buf, int buf_size)
> {
> GetBitContext gb;
> int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0;
> int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0;
> int dts_flag = -1, cts_flag = -1;
> int64_t dts = AV_NOPTS_VALUE, cts = AV_NOPTS_VALUE;
> - init_get_bits(&gb, buf, buf_size*8);
> + init_get_bits(&gb, buf, buf_size * 8);
>
> if (sl->use_au_start)
> au_start_flag = get_bits1(&gb);
> @@ -766,7 +782,7 @@ static int mpegts_push_data(MpegTSFilter *filter,
> const uint8_t *p;
> int len, code;
>
> - if(!ts->pkt)
> + if (!ts->pkt)
> return 0;
>
> if (is_start) {
> @@ -780,7 +796,7 @@ static int mpegts_push_data(MpegTSFilter *filter,
> }
> p = buf;
> while (buf_size > 0) {
> - switch(pes->state) {
> + switch (pes->state) {
> case MPEGTS_HEADER:
> len = PES_START_SIZE - pes->data_index;
> if (len > buf_size)
> @@ -791,15 +807,17 @@ static int mpegts_push_data(MpegTSFilter *filter,
> buf_size -= len;
> if (pes->data_index == PES_START_SIZE) {
> /* we got all the PES or section header. We can now
> - decide */
> + * decide */
> if (pes->header[0] == 0x00 && pes->header[1] == 0x00 &&
> pes->header[2] == 0x01) {
> /* it must be an mpeg2 PES stream */
> code = pes->header[3] | 0x100;
> - av_dlog(pes->stream, "pid=%x pes_code=%#x\n", pes->pid,
> code);
> + av_dlog(pes->stream, "pid=%x pes_code=%#x\n", pes->pid,
> + code);
>
> if ((pes->st && pes->st->discard == AVDISCARD_ALL &&
> - (!pes->sub_st || pes->sub_st->discard ==
> AVDISCARD_ALL)) ||
> + (!pes->sub_st ||
> + pes->sub_st->discard == AVDISCARD_ALL)) ||
> code == 0x1be) /* padding_stream */
> goto skip;
>
> @@ -814,7 +832,7 @@ static int mpegts_push_data(MpegTSFilter *filter,
>
> pes->total_size = AV_RB16(pes->header + 4);
> /* NOTE: a zero total size means the PES size is
> - unbounded */
> + * unbounded */
> if (!pes->total_size)
> pes->total_size = MAX_PES_PAYLOAD;
>
> @@ -830,8 +848,10 @@ static int mpegts_push_data(MpegTSFilter *filter,
> code != 0x1f8) { /* ITU-T Rec.
> H.222.1 type E stream */
> pes->state = MPEGTS_PESHEADER;
> if (pes->st->codec->codec_id == AV_CODEC_ID_NONE) {
> - av_dlog(pes->stream, "pid=%x stream_type=%x
> probing\n",
> - pes->pid, pes->stream_type);
> + av_dlog(pes->stream,
> + "pid=%x stream_type=%x probing\n",
> + pes->pid,
> + pes->stream_type);
> pes->st->codec->codec_id = AV_CODEC_ID_PROBE;
> }
> } else {
> @@ -841,14 +861,14 @@ static int mpegts_push_data(MpegTSFilter *filter,
> } else {
> /* otherwise, it should be a table */
> /* skip packet */
> - skip:
> +skip:
> pes->state = MPEGTS_SKIP;
> continue;
> }
> }
> break;
> - /**********************************************/
> - /* PES packing parsing */
> + /**********************************************/
> + /* PES packing parsing */
> case MPEGTS_PESHEADER:
> len = PES_HEADER_SIZE - pes->data_index;
> if (len < 0)
> @@ -910,7 +930,8 @@ static int mpegts_push_data(MpegTSFilter *filter,
> pes->state = MPEGTS_PAYLOAD;
> pes->data_index = 0;
> if (pes->stream_type == 0x12 && buf_size > 0) {
> - int sl_header_bytes = read_sl_header(pes, &pes->sl, p,
> buf_size);
> + int sl_header_bytes = read_sl_header(pes, &pes->sl, p,
> + buf_size);
> pes->pes_header_size += sl_header_bytes;
> p += sl_header_bytes;
> buf_size -= sl_header_bytes;
> @@ -919,14 +940,17 @@ static int mpegts_push_data(MpegTSFilter *filter,
> break;
> case MPEGTS_PAYLOAD:
> if (buf_size > 0 && pes->buffer) {
> - if (pes->data_index > 0 && pes->data_index+buf_size >
> pes->total_size) {
> + if (pes->data_index > 0 &&
> + pes->data_index + buf_size > pes->total_size) {
> new_pes_packet(pes, ts->pkt);
> pes->total_size = MAX_PES_PAYLOAD;
> - pes->buffer = av_buffer_alloc(pes->total_size +
> FF_INPUT_BUFFER_PADDING_SIZE);
> + pes->buffer = av_buffer_alloc(pes->total_size +
> +
> FF_INPUT_BUFFER_PADDING_SIZE);
> if (!pes->buffer)
> return AVERROR(ENOMEM);
> ts->stop_parse = 1;
> - } else if (pes->data_index == 0 && buf_size >
> pes->total_size) {
> + } else if (pes->data_index == 0 &&
> + buf_size > pes->total_size) {
> // pes packet size is < ts size packet and pes data is
> padded with 0xff
> // not sure if this is legal in ts but see issue #2392
> buf_size = pes->total_size;
> @@ -995,11 +1019,11 @@ static int init_MP4DescrParseContext(
this function should not go to a new line after the (
> unsigned size, Mp4Descr *descr, int max_descr_count)
> {
> int ret;
> - if (size > (1<<30))
> + if (size > (1 << 30))
> return AVERROR_INVALIDDATA;
>
> - if ((ret = ffio_init_context(&d->pb, (unsigned char*)buf, size, 0,
> - NULL, NULL, NULL, NULL)) < 0)
> + if ((ret = ffio_init_context(&d->pb, (unsigned char *)buf, size, 0,
> + NULL, NULL, NULL, NULL)) < 0)
> return ret;
>
> d->s = s;
> @@ -1355,11 +1392,14 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc,
> AVStream *st, int stream_type
> language[i + 1] = get8(pp, desc_end);
> language[i + 2] = get8(pp, desc_end);
> language[i + 3] = ',';
> - switch (get8(pp, desc_end)) {
> - case 0x01: st->disposition |= AV_DISPOSITION_CLEAN_EFFECTS;
> break;
> - case 0x02: st->disposition |= AV_DISPOSITION_HEARING_IMPAIRED;
> break;
> - case 0x03: st->disposition |= AV_DISPOSITION_VISUAL_IMPAIRED;
> break;
> - }
> + switch (get8(pp, desc_end)) {
> + case 0x01: st->disposition |= AV_DISPOSITION_CLEAN_EFFECTS;
> + break;
> + case 0x02: st->disposition |= AV_DISPOSITION_HEARING_IMPAIRED;
> + break;
> + case 0x03: st->disposition |= AV_DISPOSITION_VISUAL_IMPAIRED;
> + break;
it's safe to return a new line after a case lable
there are a few other places where this could be done
> + }
> }
> if (i) {
> language[i - 1] = 0;
> @@ -1368,7 +1408,7 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc,
> AVStream *st, int stream_type
> break;
> case 0x05: /* registration descriptor */
> st->codec->codec_tag = bytestream_get_le32(pp);
> - av_dlog(fc, "reg_desc=%.4s\n", (char*)&st->codec->codec_tag);
> + av_dlog(fc, "reg_desc=%.4s\n", (char *)&st->codec->codec_tag);
> if (st->codec->codec_id == AV_CODEC_ID_NONE)
> mpegts_find_stream_type(st, st->codec->codec_tag, REGD_types);
> break;
> @@ -1452,9 +1493,9 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t
> *section, int section_len
> if (!ts->stream->nb_streams)
> ts->stop_parse = 1;
>
> - for(;;) {
> st = 0;
> pes = NULL;
> + for (;;) {
that's not exactly cosmetics
also indentation is now off
> stream_type = get8(&p, p_end);
> if (stream_type < 0)
> break;
> @@ -1472,7 +1513,8 @@ static void pmt_cb(MpegTSFilter *filter, const uint8_t
> *section, int section_len
> }
> st = pes->st;
> } else if (stream_type != 0x13) {
> - if (ts->pids[pid]) mpegts_close_filter(ts, ts->pids[pid]);
> //wrongly added sdt filter probably
> + if (ts->pids[pid])
> + mpegts_close_filter(ts, ts->pids[pid]);
> //wrongly added sdt filter probably
nit: you could delete some spaces so that the line is less than 80 characters
> pes = add_pes_stream(ts, pid, pcr_pid);
> if (pes) {
> st = avformat_new_stream(pes->stream, NULL);
>
I'll push it with these fixes and a few others.
Vittorio
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel