[FFmpeg-devel] [PATCH]pes packetizer

realsun sunxiaohui
Wed Jun 27 12:02:57 CEST 2007


Michael Niedermayer wrote:
> Hi
>
> On Sat, Jun 23, 2007 at 06:11:29PM +0800, realsun wrote:
>   
>> Hi,
>> This is the PES packetizer code and I have made MPEG PS encoder to use
>> this packetizer and I hope this could be reused by TS muxer.
>>     
>
> please diff files against their proper parent file
>   

yes, I diffed pesenc.c against mepgenc.c

> following review of pes.c is based on a diff of it against mpegenc.c
> ive also edited the diff to place related functions adjacent to each
> other
>
>   
>> --- /home/michael/orgmpegmux/mpegenc.c	2007-06-23 23:24:43.000000000 +0200
>> +++ pes.c	2007-06-23 23:24:51.000000000 +0200
>> @@ -1,6 +1,6 @@
>>  /*
>> - * MPEG1/2 muxer
>> - * Copyright (c) 2000, 2001, 2002 Fabrice Bellard.
>> + * PES muxer.
>> + * Copyright (c) 2007 Xiaohui Sun <sunxiaohui at dsp.ac.cn>
>>   *
>>     
>
> this is not correct, you are not the only author of this code
>   
removed

>
> [...]
>
>   
>> +/*
>> + * Put timestamp into packet
>> + * @param[in] p         the stream to write
>> + * @param[in] id        stream id
>> + * @param[in] timestamp the timestamp to put in
>> + * @return  NULL
>> + */
>> +static inline void put_timestamp(uint8_t* p, int id, int64_t timestamp)
>> +{
>> +    bytestream_put_byte(&p,
>> +        (id << 4) |
>> +        (((timestamp >> 30) & 0x07) << 1) |
>> +        1);
>> +    bytestream_put_be16(&p, (uint16_t)((((timestamp >> 15) & 0x7fff) << 1) | 1));
>> +    bytestream_put_be16(&p, (uint16_t)((((timestamp) & 0x7fff) << 1) | 1));
>>  }
>>     
>
>   
>> -static inline void put_timestamp(ByteIOContext *pb, int id, int64_t timestamp)
>> -{
>> -    put_byte(pb,
>> -             (id << 4) |
>> -             (((timestamp >> 30) & 0x07) << 1) |
>> -             1);
>> -    put_be16(pb, (uint16_t)((((timestamp >> 15) & 0x7fff) << 1) | 1));
>> -    put_be16(pb, (uint16_t)((((timestamp) & 0x7fff) << 1) | 1));
>>     
>
> a change from ByteIOContext to uint8_t* belongs into a seperate patch
> the addition of doxygen comments also belongs into a seperate patch
> and so does the splitig out of functions from mpegenc.c
>
>   

this patch simply extract functions from mpegenc.c

> [...]
>
>   
>> -static int get_nb_frames(AVFormatContext *ctx, StreamInfo *stream, int len){
>> -    int nb_frames=0;
>> -    PacketDesc *pkt_desc= stream->premux_packet;
>> -
>> -    while(len>0){
>> -        if(pkt_desc->size == pkt_desc->unwritten_size)
>> -            nb_frames++;
>> -        len -= pkt_desc->unwritten_size;
>> -        pkt_desc= pkt_desc->next;
>> -    }
>> -
>> -    return nb_frames;
>> +static int get_nb_frames(AVFormatContext *ctx, PESStream *stream, int len){
>> +    int nb_frames=0;
>> +    PacketDesc *pkt_desc= stream->premux_packet;
>>  
>> +    while(len>0){
>> +        if(pkt_desc->size == pkt_desc->unwritten_size)
>> +            nb_frames++;
>> +        len -= pkt_desc->unwritten_size;
>> +        pkt_desc= pkt_desc->next;
>> +    }
>>     
>
> please dont reorder functions
>   

modified

>
> [...]
>   
>> +int pes_mux_init(AVFormatContext *ctx)
>>     
>
> non static function without proper prefi
>   

added ff_ prefix

>
> [...]
>   
>>      mpa_id = AUDIO_ID;
>>      ac3_id = AC3_ID;
>>      dts_id = DTS_ID;
>>      mpv_id = VIDEO_ID;
>>      mps_id = SUB_ID;
>>      lpcm_id = LPCM_ID;
>> -    for(i=0;i<ctx->nb_streams;i++) {
>> -        st = ctx->streams[i];
>> -        stream = av_mallocz(sizeof(StreamInfo));
>> -        if (!stream)
>> -            goto fail;
>> -        st->priv_data = stream;
>>  
>> +    for (i = 0; i < ctx->nb_streams; i++) {
>> +        st = ctx->streams[i];
>> +        stream = (PESStream*)st->priv_data;
>>     
>
> cosmetic
>   

fixed

>
>   
>>          av_set_pts_info(st, 64, 1, 90000);
>>  
>>          switch(st->codec->codec_type) {
>> @@ -336,7 +91,7 @@ static int mpeg_mux_init(AVFormatContext
>>                          break;
>>                  }
>>                  if (j == 4)
>> -                    goto fail;
>> +                    return AVERROR(ENOMEM);
>>                  if (st->codec->channels > 8)
>>                      return -1;
>>                  stream->lpcm_header[0] = 0x0c;
>> @@ -346,18 +101,13 @@ static int mpeg_mux_init(AVFormatContext
>>              } else {
>>                  stream->id = mpa_id++;
>>              }
>> -
>>              /* This value HAS to be used for VCD (see VCD standard, p. IV-7).
>> -               Right now it is also used for everything else.*/
>> +             Right now it is also used for everything else.*/
>>              stream->max_buffer_size = 4 * 1024;
>>     
>
> cosmetic
>   

fixed

>
>   
>> -            s->audio_bound++;
>> +
>>     
>
>   
>>              break;
>>          case CODEC_TYPE_VIDEO:
>>              stream->id = mpv_id++;
>> -            if (st->codec->rc_buffer_size)
>> -                stream->max_buffer_size = 6*1024 + st->codec->rc_buffer_size/8;
>> -            else
>> -                stream->max_buffer_size = 230*1024; //FIXME this is probably too small as default
>>  #if 0
>>                  /* see VCD standard, p. IV-7*/
>>                  stream->max_buffer_size = 46 * 1024;
>> @@ -366,7 +116,10 @@ static int mpeg_mux_init(AVFormatContext
>>                     Right now it is also used for everything else.*/
>>                  stream->max_buffer_size = 230 * 1024;
>>  #endif
>> -            s->video_bound++;
>> +            if (st->codec->rc_buffer_size)
>> +                stream->max_buffer_size = 6*1024 + st->codec->rc_buffer_size/8;
>> +            else
>> +                stream->max_buffer_size = 230*1024; //FIXME this is probably too small as default
>>              break;
>>     
>
> cosmetic
>   

fixed

[...]

>
> ------------------------------------------------------------------------
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at mplayerhq.hu
> http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: pes.diff
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070627/7fea5b1c/attachment.asc>



More information about the ffmpeg-devel mailing list