On Thu, May 31, 2012 at 02:03:38PM -0700, Luca Barbato wrote:
> Format switch statements and cleanup.
> ---
> libavformat/flvdec.c | 483
> ++++++++++++++++++++++++++++----------------------
> 1 files changed, 275 insertions(+), 208 deletions(-)
flvdec: K&R formatting cosmetics
> --- a/libavformat/flvdec.c
> +++ b/libavformat/flvdec.c
> @@ -77,72 +80,96 @@ static AVStream *create_stream(AVFormatContext *s, int
> tag, int codec_type)
>
> -static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream,
> AVCodecContext *acodec, int flv_codecid) {
> - switch(flv_codecid) {
> - //no distinction between S16 and S8 PCM codec flags
> - case FLV_CODECID_PCM:
> - acodec->codec_id = acodec->bits_per_coded_sample == 8 ?
> CODEC_ID_PCM_U8 :
> +static void flv_set_audio_codec(AVFormatContext *s,
> + AVStream *astream,
> + AVCodecContext *acodec, int flv_codecid)
> +{
> + switch (flv_codecid) {
> + //no distinction between S16 and S8 PCM codec flags
space after //
> + case FLV_CODECID_PCM:
> + acodec->codec_id = acodec->bits_per_coded_sample == 8 ?
> CODEC_ID_PCM_U8 :
> #if HAVE_BIGENDIAN
> - CODEC_ID_PCM_S16BE;
> + CODEC_ID_PCM_S16BE;
> #else
> - CODEC_ID_PCM_S16LE;
> + CODEC_ID_PCM_S16LE;
> #endif
Indentation looks off by one space here. I'd suggest moving the ':'
below the ifdef as well.
> + case FLV_CODECID_PCM_LE:
> + acodec->codec_id = acodec->bits_per_coded_sample == 8 ?
> CODEC_ID_PCM_U8 : CODEC_ID_PCM_S16LE;
Maybe
acodec->codec_id = acodec->bits_per_coded_sample == 8 ? CODEC_ID_PCM_U8
: CODEC_ID_PCM_S16LE;
though that does not really keep the line below 80 characters either...
> + case FLV_CODECID_NELLYMOSER_8KHZ_MONO:
> + acodec->sample_rate = 8000; //in case metadata does not otherwise
> declare samplerate
Space after // and you could move the comment to the previous line.
> switch(flv_codecid) {
switch (
> - vcodec->extradata = av_malloc(1);
> + vcodec->extradata = av_malloc(1);
> if(length >= buffsize) {
if (
> @@ -168,7 +198,8 @@ static int parse_keyframes_index(AVFormatContext *s,
> AVIOContext *ioc, AVStream
>
> - while (avio_tell(ioc) < max_pos - 2 && amf_get_string(ioc, str_val,
> sizeof(str_val)) > 0) {
> + while (avio_tell(ioc) < max_pos - 2 &&
> + amf_get_string(ioc, str_val, sizeof(str_val)) > 0) {
> int64_t* current_array;
int64_t *current_array;
> @@ -180,8 +211,8 @@ static int parse_keyframes_index(AVFormatContext *s,
> AVIOContext *ioc, AVStream
>
> /*
> - * Expect only 'times' or 'filepositions' sub-arrays in other case
> refuse to use such metadata
> - * for indexing
> + * Expect only 'times' or 'filepositions' sub-arrays in other case
> + * refuse to use such metadata for indexing
Expect only 'times' or 'filepositions' sub-arrays; in other case
refuse to use such metadata for indexing.
> @@ -250,59 +285,66 @@ static int amf_parse_object(AVFormatContext *s,
> AVStream *astream, AVStream *vst
>
> switch(amf_type) {
switch (
> + case AMF_DATA_TYPE_STRING:
> + if(amf_get_string(ioc, str_val, sizeof(str_val)) < 0)
if (
> + if (amf_parse_object(s, astream, vstream, str_val,
> + max_pos, depth + 1) < 0)
> + return -1; //if we couldn't skip, bomb out.
space after //
> + case AMF_DATA_TYPE_UNSUPPORTED:
> + break; //these take up no additional space
ditto
> + case AMF_DATA_TYPE_MIXEDARRAY:
> + avio_skip(ioc, 4); //skip 32-bit max array index
again
> + while(avio_tell(ioc) < max_pos - 2 &&
while (
> + amf_get_string(ioc, str_val, sizeof(str_val)) > 0) {
> + //this is the only case in which we would want a nested parse to
> not skip over the object
more and this is a long line
> + if(avio_r8(ioc) != AMF_END_OF_OBJECT)
if (
> + if (amf_parse_object(s, NULL, NULL, NULL, max_pos, depth + 1) <
> 0)
> + return -1; //if we couldn't skip, bomb out.
space after //
> + case AMF_DATA_TYPE_DATE:
> + avio_skip(ioc, 8 + 2); //timestamp (double) and UTC offset (int16)
> + break;
> + default: //unsupported type, we couldn't skip
> + return -1;
same
> - if(depth == 1 && key) { //only look for metadata values when we are not
> nested and key != NULL
> + //only look for metadata values when we are not nested and key != NULL
same
> @@ -371,14 +414,19 @@ static int flv_read_metabody(AVFormatContext *s,
> int64_t next_pos) {
>
> - //find the streams now so that amf_parse_object doesn't need to do the
> lookup every time it is called.
> + /*
> + * find the streams now so that amf_parse_object does not need
> + * to do the lookup every time it is called.
> + */
I'd put that on two lines instead of four.
> for(i = 0; i < s->nb_streams; i++) {
for (
> - //parse the second object (we want a mixed array)
> + // parse the second object (we want a mixed array)
> if(amf_parse_object(s, astream, vstream, buffer, next_pos, 0) < 0)
if (
> @@ -395,7 +443,9 @@ static int flv_read_header(AVFormatContext *s)
> if (!flags) {
> flags = FLV_HEADER_FLAG_HASVIDEO | FLV_HEADER_FLAG_HASAUDIO;
> - av_log(s, AV_LOG_WARNING, "Broken FLV file, which says no streams
> present, this might fail\n");
> + av_log(s, AV_LOG_WARNING,
> + "Broken FLV file, which says no streams present, "
> + "this might fail\n");
> }
>
> if((flags & (FLV_HEADER_FLAG_HASVIDEO|FLV_HEADER_FLAG_HASAUDIO))
if (
> @@ -536,99 +587,107 @@ static int flv_read_packet(AVFormatContext *s,
> AVPacket *pkt)
>
> - for(;;avio_skip(s->pb, 4)){ /* pkt size is repeated at end. skip it */
> -
> + for(;;avio_skip(s->pb, 4)) { /* pkt size is repeated at end. skip it */
for (, space after ';'
> + next= size + avio_tell(s->pb);
space before =
> + } else {
> + if (type == FLV_TAG_TYPE_META && size > 13 + 1 + 4)
> + if (flv_read_metabody(s, next) > 0) {
> + return flv_data_packet(s, pkt, dts, next);
> + }
maybe drop {}
> + /* now find stream */
> + for(i=0;i<s->nb_streams;i++) {
lots of spaces missing
> + if ((st->discard >= AVDISCARD_NONKEY &&
> + !((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY ||
> + is_audio)) ||
> + (st->discard >= AVDISCARD_BIDIR &&
> + ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_DISP_INTER &&
> + !is_audio)) ||
> + st->discard >= AVDISCARD_ALL
> + ) {
Move the last line to the previous.
> - avio_seek(s->pb, fsize-3-size, SEEK_SET);
> - if(size == avio_rb24(s->pb) + 11){
> + avio_seek(s->pb, fsize - 3 - size, SEEK_SET);
> + if(size == avio_rb24(s->pb) + 11) {
if (
> @@ -665,11 +727,14 @@ static int flv_read_packet(AVFormatContext *s, AVPacket
> *pkt)
> if (st->codec->codec_id == CODEC_ID_H264) {
> - int32_t cts = (avio_rb24(s->pb)+0xff800000)^0xff800000; // sign
> extension
> + // sign extension
> + int32_t cts = (avio_rb24(s->pb) + 0xff800000)^0xff800000;
space around ^
Diego
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel