[FFmpeg-devel] [PATCH 1/1] Extended ASF functionality

Michael Niedermayer michaelni at gmx.at
Wed Jul 1 15:21:52 CEST 2015


On Wed, Jul 01, 2015 at 03:49:11PM +0300, Vadim Belov wrote:
> ---
>  libavformat/Makefile             |   2 +-
>  libavformat/asf.c                |   4 +
>  libavformat/asf.h                |  12 ++-
>  libavformat/asf_ex.h             |  58 ++++++++++
>  libavformat/asf_trim.c           | 228 +++++++++++++++++++++++++++++++++++++++
>  libavformat/asf_trim.h           |  95 ++++++++++++++++
>  libavformat/asfdec.c             |  17 ++-
>  libavformat/asfenc.c             |  64 ++++++++++-
>  8 files changed, 954 insertions(+), 485 deletions(-)
>  create mode 100644 libavformat/asf_ex.h
>  create mode 100644 libavformat/asf_trim.c
>  create mode 100644 libavformat/asf_trim.h
> 
>  1.9.5.msysgit.1
> 
>  Signed-off-by: Vadim Belov <vadim.belov at gmail.com>
> 
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index bca9d5b..2743467 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -84,7 +84,7 @@ OBJS-$(CONFIG_APNG_MUXER)                += apngenc.o
>  OBJS-$(CONFIG_AQTITLE_DEMUXER)           += aqtitledec.o subtitles.o
>  OBJS-$(CONFIG_ASF_DEMUXER)               += asfdec.o asf.o asfcrypt.o \
>                                              avlanguage.o
> -OBJS-$(CONFIG_ASF_MUXER)                 += asfenc.o asf.o
> +OBJS-$(CONFIG_ASF_MUXER)                 += asfenc.o asf.o asf_trim.o
>  OBJS-$(CONFIG_ASS_DEMUXER)               += assdec.o subtitles.o
>  OBJS-$(CONFIG_ASS_MUXER)                 += assenc.o
>  OBJS-$(CONFIG_AST_DEMUXER)               += ast.o astdec.o
> diff --git a/libavformat/asf.c b/libavformat/asf.c
> index 80d24db..d2a0a8f 100644
> --- a/libavformat/asf.c
> +++ b/libavformat/asf.c
> @@ -143,6 +143,10 @@ const ff_asf_guid ff_asf_digital_signature = {
>      0xfc, 0xb3, 0x11, 0x22, 0x23, 0xbd, 0xd2, 0x11, 0xb4, 0xb7, 0x00, 0xa0, 0xc9, 0x55, 0xfc, 0x6e
>  };
>  
> +const ff_asf_guid ff_asf_index_header = {
> +    0xd3, 0x29, 0xe2, 0xd6, 0xda, 0x35, 0xd1, 0x11, 0x90, 0x34, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xbe
> +};
> +
>  /* List of official tags at http://msdn.microsoft.com/en-us/library/dd743066(VS.85).aspx */
>  const AVMetadataConv ff_asf_metadata_conv[] = {
>      { "WM/AlbumArtist",          "album_artist"     },
> diff --git a/libavformat/asf.h b/libavformat/asf.h
> index 0c9598a..0ef4ea6 100644
> --- a/libavformat/asf.h
> +++ b/libavformat/asf.h
> @@ -1,5 +1,6 @@
>  /*
>   * Copyright (c) 2000, 2001 Fabrice Bellard
> + * Copyright (c) 2015 Vadim Belov
>   *
>   * This file is part of FFmpeg.
>   *
> @@ -28,6 +29,11 @@
>  
>  #define PACKET_SIZE 3200
>  
> +/** 
> + * "asf_ex.h" is IMPORTANT to be placed After PACKET_SIZE definition
> + */
> +#include "asf_ex.h"
> +
>  typedef struct ASFPayload {
>      uint8_t type;
>      uint16_t size;
> @@ -57,7 +63,9 @@ typedef struct ASFStream {
>      uint32_t palette[256];
>  
>      int payload_ext_ct;
> -    ASFPayload payload[8];
> +    ASFPayload payload[8];	
> +
> +    ASFIndexData idx_data;
>  } ASFStream;
>  
>  typedef struct ASFMainHeader {
> @@ -123,7 +131,7 @@ extern const ff_asf_guid ff_asf_language_guid;
>  extern const ff_asf_guid ff_asf_content_encryption;
>  extern const ff_asf_guid ff_asf_ext_content_encryption;
>  extern const ff_asf_guid ff_asf_digital_signature;
> -
> +extern const ff_asf_guid ff_asf_index_header;
>  extern const AVMetadataConv ff_asf_metadata_conv[];
>  
>  #define ASF_PACKET_FLAG_ERROR_CORRECTION_PRESENT 0x80 //1000 0000
> diff --git a/libavformat/asf_ex.h b/libavformat/asf_ex.h
> new file mode 100644
> index 0000000..480105a
> --- /dev/null
> +++ b/libavformat/asf_ex.h
> @@ -0,0 +1,58 @@
> +/**
> + * @file asf_ex.h
> + * Extensions to ASF handling
> + * @author Vadim Belov
> + *
> + * Copyright (c) 2015 Vadim Belov
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#ifndef AVFORMAT_ASF_EX_H
> +#define AVFORMAT_ASF_EX_H
> +
> +#include <stdint.h>
> +

> +/**
> + * Packet size according to the size that Custom ASF File Creator writes 
> + * to its output packets:
> + * ASF_PACKET_SIZE is 8192, but is decremented later.
> + * Final result: in the ASF core file the value is 8032 
> + */
> +#ifdef PACKET_SIZE
> +#undef PACKET_SIZE
> +#endif
> +#define PACKET_SIZE 8032 

is this specific value needed ?
are there any disadvantages in using it ?

either way if its changed it should be changed not overriden by undef
also PACKET_SIZE could be moved to asfenc.c in a seperate patch

it could even be made user configurable if theres an advantage in
the user choosing the packet size


> +
> +#define STREAM_DIRECTION_STR "streamDirection"
> +#define DIRECTION_DICT_KEY "direction"
> +#define NO_STREAM_DIRECTION -1
> +#define ASF_MAX_STREAMS_NUM 128
> +
> +typedef struct ASFStreamIndex { // Index Entry value 
> +    uint64_t offset;
> +} ASFStreamIndex;
> +

> +typedef struct ASFIndexData { 
> +    ASFStreamIndex* indices;	// array of ASFStreamIndex
> +    uint32_t indices_max_count; // allocated size
> +    uint32_t next_duration_mark; // for next index
> +    uint32_t indices_count;		 // current index 
> +    int64_t  duration_overall;
> +} ASFIndexData;

please replace tabs by spaces, they cannot be pushed  to ffmpeg git


> +
> +#endif /* AVFORMAT_ASF_EX_H */
> diff --git a/libavformat/asf_trim.c b/libavformat/asf_trim.c
> new file mode 100644
> index 0000000..ce75170
> --- /dev/null
> +++ b/libavformat/asf_trim.c
> @@ -0,0 +1,228 @@
> +/*
> + * @file asf_trim.c
> + * Extensions to ASF handling
> + * @author Vadim Belov
> + *
> + * Copyright (c) 2015 Vadim Belov
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> +*/
> +
> +#include "asf_trim.h"
> +
> +#define ASF_INDEX_ENTRY_TIME_INTERVAL 10000
> +#define SPECIFIER_INDEX_TYPE 3
> +
> +#define BLOCK_PART      0xFFFFFFFF00000000
> +#define OFFSET_PART     0x00000000FFFFFFFF
> +#define INVALID_OFFSET  0xFFFFFFFF
> +
> +int asf_get_streams_direction(AVFormatContext *s)
> +{
> +    int ret = 0;
> +    int n;
> +    for (n = 0; n < s->nb_streams; n++) {
> +        AVDictionaryEntry *t = av_dict_get(
> +            s->streams[n]->metadata, DIRECTION_DICT_KEY, NULL, 0);
> +        
> +        av_log(s, AV_LOG_DEBUG, "direction metadata ptr is %p\n", t);
> +
> +        if (t) ret++;
> +    }
> +    return ret;
> +}
> +

> +void set_stream_direction(
> +    AVFormatContext *s,
> +    int direction[ASF_MAX_STREAMS_NUM],
> +    AVStream *st,
> +    int i)
> +{

non static functions need a ff_ prefix (or other prefix if they are
public to the end user but here it should be ff_)

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Why not whip the teacher when the pupil misbehaves? -- Diogenes of Sinope
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20150701/a22e15b1/attachment.asc>


More information about the ffmpeg-devel mailing list