[FFmpeg-devel] [PATCHv2] libopenmpt: add subsong support

Nicolas George george at nsup.org
Mon Jul 18 18:36:18 EEST 2016


Le primidi 1er thermidor, an CCXXIV, Josh de Kock a écrit :
> ---
>  libavformat/libopenmpt.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/libavformat/libopenmpt.c b/libavformat/libopenmpt.c
> index 58a02be..286a908 100644
> --- a/libavformat/libopenmpt.c
> +++ b/libavformat/libopenmpt.c
> @@ -36,6 +36,7 @@ typedef struct OpenMPTContext {
>      /* options */
>      int sample_rate;
>      int64_t layout;
> +    int subsong;
>  } OpenMPTContext;
>  
>  #define OFFSET(x) offsetof(OpenMPTContext, x)
> @@ -44,6 +45,7 @@ typedef struct OpenMPTContext {
>  static const AVOption options[] = {
>      {"sample_rate", "set sample rate",    OFFSET(sample_rate), AV_OPT_TYPE_INT,            {.i64 = 48000},                   1000, INT_MAX,   A|D},
>      {"layout",      "set channel layout", OFFSET(layout),      AV_OPT_TYPE_CHANNEL_LAYOUT, {.i64 = AV_CH_LAYOUT_STEREO},     0,    INT64_MAX, A|D},

> +    {"subsong",     "set subsong",        OFFSET(subsong),     AV_OPT_TYPE_INT,            {.i64 = -2},                      -2,   INT_MAX,   A|D},

Missing documentation about -2 = default and -1 = all. It could be constants
associated to the option, maybe.

>      {NULL}
>  };
>  
> @@ -70,6 +72,7 @@ static int read_header_openmpt(AVFormatContext *s)
>      OpenMPTContext *openmpt = s->priv_data;
>      int64_t size = avio_size(s->pb);
>      char *buf = av_malloc(size);
> +    char str[5];
>  
>      if (!buf)
>          return AVERROR(ENOMEM);
> @@ -88,6 +91,17 @@ static int read_header_openmpt(AVFormatContext *s)
>      add_meta(s, "encoder", openmpt_module_get_metadata(openmpt->module, "tracker"));
>      add_meta(s, "comment", openmpt_module_get_metadata(openmpt->module, "message"));
>  

> +    if (openmpt->subsong >= openmpt_module_get_num_subsongs(openmpt->module))
> +        openmpt->subsong = -2;

IMHO, an error would be more correct.

> +
> +    if (openmpt->subsong != -2) {

> +        if (openmpt->subsong >= 0) {
> +            snprintf(str, sizeof(str), "%d", openmpt->subsong + 1);
> +            av_dict_set(&s->metadata, "track", str, 0);
> +        }

av_dict_set_int(); and str would have been too short.

> +        openmpt_module_select_subsong(openmpt->module, openmpt->subsong);
> +    }
> +
>      st = avformat_new_stream(s, NULL);
>      if (!st) {
>          openmpt_module_destroy(openmpt->module);

Regards,

-- 
  Nicolas George
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20160718/a6f2f6d8/attachment.sig>


More information about the ffmpeg-devel mailing list