FFmpeg
af_ashowinfo.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Stefano Sabatini
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * filter for showing textual audio frame information
24  */
25 
26 #include <inttypes.h>
27 #include <stddef.h>
28 
29 #include "libavutil/adler32.h"
30 #include "libavutil/attributes.h"
32 #include "libavutil/common.h"
33 #include "libavutil/downmix_info.h"
34 #include "libavutil/intreadwrite.h"
35 #include "libavutil/mem.h"
36 #include "libavutil/replaygain.h"
37 #include "libavutil/timestamp.h"
38 #include "libavutil/samplefmt.h"
39 
40 #include "libavcodec/defs.h"
41 
42 #include "audio.h"
43 #include "avfilter.h"
44 #include "internal.h"
45 
46 typedef struct AShowInfoContext {
47  /**
48  * Scratch space for individual plane checksums for planar audio
49  */
50  uint32_t *plane_checksums;
52 
54 {
55  AShowInfoContext *s = ctx->priv;
56  av_freep(&s->plane_checksums);
57 }
58 
60 {
61  enum AVMatrixEncoding enc;
62 
63  av_log(ctx, AV_LOG_INFO, "matrix encoding: ");
64 
65  if (sd->size < sizeof(enum AVMatrixEncoding)) {
66  av_log(ctx, AV_LOG_INFO, "invalid data");
67  return;
68  }
69 
70  enc = *(enum AVMatrixEncoding *)sd->data;
71  switch (enc) {
72  case AV_MATRIX_ENCODING_NONE: av_log(ctx, AV_LOG_INFO, "none"); break;
73  case AV_MATRIX_ENCODING_DOLBY: av_log(ctx, AV_LOG_INFO, "Dolby Surround"); break;
74  case AV_MATRIX_ENCODING_DPLII: av_log(ctx, AV_LOG_INFO, "Dolby Pro Logic II"); break;
75  case AV_MATRIX_ENCODING_DPLIIX: av_log(ctx, AV_LOG_INFO, "Dolby Pro Logic IIx"); break;
76  case AV_MATRIX_ENCODING_DPLIIZ: av_log(ctx, AV_LOG_INFO, "Dolby Pro Logic IIz"); break;
77  case AV_MATRIX_ENCODING_DOLBYEX: av_log(ctx, AV_LOG_INFO, "Dolby EX"); break;
78  case AV_MATRIX_ENCODING_DOLBYHEADPHONE: av_log(ctx, AV_LOG_INFO, "Dolby Headphone"); break;
79  default: av_log(ctx, AV_LOG_WARNING, "unknown"); break;
80  }
81 }
82 
84 {
85  AVDownmixInfo *di;
86 
87  av_log(ctx, AV_LOG_INFO, "downmix: ");
88  if (sd->size < sizeof(*di)) {
89  av_log(ctx, AV_LOG_INFO, "invalid data");
90  return;
91  }
92 
93  di = (AVDownmixInfo *)sd->data;
94 
95  av_log(ctx, AV_LOG_INFO, "preferred downmix type - ");
96  switch (di->preferred_downmix_type) {
97  case AV_DOWNMIX_TYPE_LORO: av_log(ctx, AV_LOG_INFO, "Lo/Ro"); break;
98  case AV_DOWNMIX_TYPE_LTRT: av_log(ctx, AV_LOG_INFO, "Lt/Rt"); break;
99  case AV_DOWNMIX_TYPE_DPLII: av_log(ctx, AV_LOG_INFO, "Dolby Pro Logic II"); break;
100  default: av_log(ctx, AV_LOG_WARNING, "unknown"); break;
101  }
102 
103  av_log(ctx, AV_LOG_INFO, " Mix levels: center %f (%f ltrt) - "
104  "surround %f (%f ltrt) - lfe %f",
107  di->lfe_mix_level);
108 }
109 
110 static void print_gain(AVFilterContext *ctx, const char *str, int32_t gain)
111 {
112  av_log(ctx, AV_LOG_INFO, "%s - ", str);
113  if (gain == INT32_MIN)
114  av_log(ctx, AV_LOG_INFO, "unknown");
115  else
116  av_log(ctx, AV_LOG_INFO, "%f", gain / 100000.0f);
117  av_log(ctx, AV_LOG_INFO, ", ");
118 }
119 
120 static void print_peak(AVFilterContext *ctx, const char *str, uint32_t peak)
121 {
122  av_log(ctx, AV_LOG_INFO, "%s - ", str);
123  if (!peak)
124  av_log(ctx, AV_LOG_INFO, "unknown");
125  else
126  av_log(ctx, AV_LOG_INFO, "%f", (float)peak / UINT32_MAX);
127  av_log(ctx, AV_LOG_INFO, ", ");
128 }
129 
131 {
132  AVReplayGain *rg;
133 
134  av_log(ctx, AV_LOG_INFO, "replaygain: ");
135  if (sd->size < sizeof(*rg)) {
136  av_log(ctx, AV_LOG_INFO, "invalid data");
137  return;
138  }
139  rg = (AVReplayGain*)sd->data;
140 
141  print_gain(ctx, "track gain", rg->track_gain);
142  print_peak(ctx, "track peak", rg->track_peak);
143  print_gain(ctx, "album gain", rg->album_gain);
144  print_peak(ctx, "album peak", rg->album_peak);
145 }
146 
148 {
149  enum AVAudioServiceType *ast;
150 
151  av_log(ctx, AV_LOG_INFO, "audio service type: ");
152  if (sd->size < sizeof(*ast)) {
153  av_log(ctx, AV_LOG_INFO, "invalid data");
154  return;
155  }
156  ast = (enum AVAudioServiceType*)sd->data;
157  switch (*ast) {
158  case AV_AUDIO_SERVICE_TYPE_MAIN: av_log(ctx, AV_LOG_INFO, "Main Audio Service"); break;
159  case AV_AUDIO_SERVICE_TYPE_EFFECTS: av_log(ctx, AV_LOG_INFO, "Effects"); break;
160  case AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED: av_log(ctx, AV_LOG_INFO, "Visually Impaired"); break;
161  case AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED: av_log(ctx, AV_LOG_INFO, "Hearing Impaired"); break;
162  case AV_AUDIO_SERVICE_TYPE_DIALOGUE: av_log(ctx, AV_LOG_INFO, "Dialogue"); break;
163  case AV_AUDIO_SERVICE_TYPE_COMMENTARY: av_log(ctx, AV_LOG_INFO, "Commentary"); break;
164  case AV_AUDIO_SERVICE_TYPE_EMERGENCY: av_log(ctx, AV_LOG_INFO, "Emergency"); break;
165  case AV_AUDIO_SERVICE_TYPE_VOICE_OVER: av_log(ctx, AV_LOG_INFO, "Voice Over"); break;
166  case AV_AUDIO_SERVICE_TYPE_KARAOKE: av_log(ctx, AV_LOG_INFO, "Karaoke"); break;
167  default: av_log(ctx, AV_LOG_INFO, "unknown"); break;
168  }
169 }
170 
172 {
173  av_log(ctx, AV_LOG_INFO, "unknown side data type: %d, size "
174  "%"SIZE_SPECIFIER" bytes", sd->type, sd->size);
175 }
176 
178 {
179  AVFilterContext *ctx = inlink->dst;
180  AShowInfoContext *s = ctx->priv;
181  char chlayout_str[128];
182  uint32_t checksum = 0;
183  int channels = inlink->channels;
185  int block_align = av_get_bytes_per_sample(buf->format) * (planar ? 1 : channels);
186  int data_size = buf->nb_samples * block_align;
187  int planes = planar ? channels : 1;
188  int i;
189  void *tmp_ptr = av_realloc_array(s->plane_checksums, channels, sizeof(*s->plane_checksums));
190 
191  if (!tmp_ptr)
192  return AVERROR(ENOMEM);
193  s->plane_checksums = tmp_ptr;
194 
195  for (i = 0; i < planes; i++) {
196  uint8_t *data = buf->extended_data[i];
197 
198  s->plane_checksums[i] = av_adler32_update(0, data, data_size);
199  checksum = i ? av_adler32_update(checksum, data, data_size) :
200  s->plane_checksums[0];
201  }
202 
203  av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), buf->channels,
204  buf->channel_layout);
205 
207  "n:%"PRId64" pts:%s pts_time:%s pos:%"PRId64" "
208  "fmt:%s channels:%d chlayout:%s rate:%d nb_samples:%d "
209  "checksum:%08"PRIX32" ",
210  inlink->frame_count_out,
211  av_ts2str(buf->pts), av_ts2timestr(buf->pts, &inlink->time_base),
212  buf->pkt_pos,
213  av_get_sample_fmt_name(buf->format), buf->channels, chlayout_str,
214  buf->sample_rate, buf->nb_samples,
215  checksum);
216 
217  av_log(ctx, AV_LOG_INFO, "plane_checksums: [ ");
218  for (i = 0; i < planes; i++)
219  av_log(ctx, AV_LOG_INFO, "%08"PRIX32" ", s->plane_checksums[i]);
220  av_log(ctx, AV_LOG_INFO, "]\n");
221 
222  for (i = 0; i < buf->nb_side_data; i++) {
223  AVFrameSideData *sd = buf->side_data[i];
224 
225  av_log(ctx, AV_LOG_INFO, " side data - ");
226  switch (sd->type) {
228  case AV_FRAME_DATA_DOWNMIX_INFO: dump_downmix (ctx, sd); break;
229  case AV_FRAME_DATA_REPLAYGAIN: dump_replaygain(ctx, sd); break;
231  default: dump_unknown (ctx, sd); break;
232  }
233 
234  av_log(ctx, AV_LOG_INFO, "\n");
235  }
236 
237  return ff_filter_frame(inlink->dst->outputs[0], buf);
238 }
239 
240 static const AVFilterPad inputs[] = {
241  {
242  .name = "default",
243  .type = AVMEDIA_TYPE_AUDIO,
244  .filter_frame = filter_frame,
245  },
246 };
247 
248 static const AVFilterPad outputs[] = {
249  {
250  .name = "default",
251  .type = AVMEDIA_TYPE_AUDIO,
252  },
253 };
254 
256  .name = "ashowinfo",
257  .description = NULL_IF_CONFIG_SMALL("Show textual information for each audio frame."),
258  .priv_size = sizeof(AShowInfoContext),
259  .uninit = uninit,
262 };
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
outputs
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1019
dump_unknown
static void dump_unknown(AVFilterContext *ctx, AVFrameSideData *sd)
Definition: af_ashowinfo.c:171
AVFrame::nb_side_data
int nb_side_data
Definition: frame.h:498
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_get_channel_layout_string
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
Definition: channel_layout.c:217
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:396
AVReplayGain::album_gain
int32_t album_gain
Same as track_gain, but for the whole album.
Definition: replaygain.h:43
data
const char data[16]
Definition: mxf.c:143
AV_AUDIO_SERVICE_TYPE_VOICE_OVER
@ AV_AUDIO_SERVICE_TYPE_VOICE_OVER
Definition: defs.h:65
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:153
replaygain.h
AVDownmixInfo::surround_mix_level_ltrt
double surround_mix_level_ltrt
Absolute scale factor representing the nominal level of the surround channels during an Lt/Rt compati...
Definition: downmix_info.h:86
ff_af_ashowinfo
const AVFilter ff_af_ashowinfo
Definition: af_ashowinfo.c:255
AV_FRAME_DATA_MATRIXENCODING
@ AV_FRAME_DATA_MATRIXENCODING
The data is the AVMatrixEncoding enum defined in libavutil/channel_layout.h.
Definition: frame.h:67
samplefmt.h
AVDownmixInfo
This structure describes optional metadata relevant to a downmix procedure.
Definition: downmix_info.h:58
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:50
planes
static const struct @318 planes[]
AVFrameSideData::size
size_t size
Definition: frame.h:212
av_cold
#define av_cold
Definition: attributes.h:90
AV_MATRIX_ENCODING_DOLBY
@ AV_MATRIX_ENCODING_DOLBY
Definition: channel_layout.h:122
AShowInfoContext::plane_checksums
uint32_t * plane_checksums
Scratch space for individual plane checksums for planar audio.
Definition: af_ashowinfo.c:50
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: af_ashowinfo.c:177
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:224
AVFrame::channels
int channels
number of audio channels, only used for audio.
Definition: frame.h:592
dump_downmix
static void dump_downmix(AVFilterContext *ctx, AVFrameSideData *sd)
Definition: af_ashowinfo.c:83
AVFrame::pkt_pos
int64_t pkt_pos
reordered pos from the last AVPacket that has been input into the decoder
Definition: frame.h:557
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_FRAME_DATA_AUDIO_SERVICE_TYPE
@ AV_FRAME_DATA_AUDIO_SERVICE_TYPE
This side data must be associated with an audio frame and corresponds to enum AVAudioServiceType defi...
Definition: frame.h:113
av_sample_fmt_is_planar
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:112
ctx
AVFormatContext * ctx
Definition: movenc.c:48
channels
channels
Definition: aptx.h:33
AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED
@ AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED
Definition: defs.h:61
AV_MATRIX_ENCODING_DPLIIX
@ AV_MATRIX_ENCODING_DPLIIX
Definition: channel_layout.h:124
av_get_sample_fmt_name
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition: samplefmt.c:49
AVReplayGain::track_peak
uint32_t track_peak
Peak track amplitude, with 100000 representing full scale (but values may overflow).
Definition: replaygain.h:39
f
#define f(width, name)
Definition: cbs_vp9.c:255
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:152
AVMatrixEncoding
AVMatrixEncoding
Definition: channel_layout.h:120
AV_MATRIX_ENCODING_DOLBYHEADPHONE
@ AV_MATRIX_ENCODING_DOLBYHEADPHONE
Definition: channel_layout.h:127
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_ashowinfo.c:53
dump_matrixenc
static void dump_matrixenc(AVFilterContext *ctx, AVFrameSideData *sd)
Definition: af_ashowinfo.c:59
AVDownmixInfo::surround_mix_level
double surround_mix_level
Absolute scale factor representing the nominal level of the surround channels during a regular downmi...
Definition: downmix_info.h:80
adler32.h
AV_AUDIO_SERVICE_TYPE_EMERGENCY
@ AV_AUDIO_SERVICE_TYPE_EMERGENCY
Definition: defs.h:64
print_gain
static void print_gain(AVFilterContext *ctx, const char *str, int32_t gain)
Definition: af_ashowinfo.c:110
AVAudioServiceType
AVAudioServiceType
Definition: defs.h:57
av_adler32_update
AVAdler av_adler32_update(AVAdler adler, const uint8_t *buf, size_t len)
Calculate the Adler32 checksum of a buffer.
Definition: adler32.c:44
av_ts2timestr
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:76
AV_FRAME_DATA_REPLAYGAIN
@ AV_FRAME_DATA_REPLAYGAIN
ReplayGain information in the form of the AVReplayGain struct.
Definition: frame.h:76
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
AVFrame::sample_rate
int sample_rate
Sample rate of the audio data.
Definition: frame.h:458
AV_MATRIX_ENCODING_NONE
@ AV_MATRIX_ENCODING_NONE
Definition: channel_layout.h:121
dump_audio_service_type
static void dump_audio_service_type(AVFilterContext *ctx, AVFrameSideData *sd)
Definition: af_ashowinfo.c:147
print_peak
static void print_peak(AVFilterContext *ctx, const char *str, uint32_t peak)
Definition: af_ashowinfo.c:120
AVFrameSideData::data
uint8_t * data
Definition: frame.h:211
AVDownmixInfo::center_mix_level_ltrt
double center_mix_level_ltrt
Absolute scale factor representing the nominal level of the center channel during an Lt/Rt compatible...
Definition: downmix_info.h:74
AVReplayGain::track_gain
int32_t track_gain
Track replay gain in microbels (divide by 100000 to get the value in dB).
Definition: replaygain.h:34
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:376
AVFrame::channel_layout
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:463
attributes.h
AVDownmixInfo::lfe_mix_level
double lfe_mix_level
Absolute scale factor representing the level at which the LFE data is mixed into L/R channels during ...
Definition: downmix_info.h:92
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
internal.h
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:369
i
int i
Definition: input.c:406
AVDownmixInfo::center_mix_level
double center_mix_level
Absolute scale factor representing the nominal level of the center channel during a regular downmix.
Definition: downmix_info.h:68
downmix_info.h
av_get_bytes_per_sample
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:106
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:350
common.h
AVDownmixInfo::preferred_downmix_type
enum AVDownmixType preferred_downmix_type
Type of downmix preferred by the mastering engineer.
Definition: downmix_info.h:62
AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED
@ AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED
Definition: defs.h:60
AV_DOWNMIX_TYPE_LORO
@ AV_DOWNMIX_TYPE_LORO
Lo/Ro 2-channel downmix (Stereo).
Definition: downmix_info.h:46
AVFrame::side_data
AVFrameSideData ** side_data
Definition: frame.h:497
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:56
inputs
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:240
AShowInfoContext
Definition: af_ashowinfo.c:46
AVFilter
Filter definition.
Definition: avfilter.h:149
checksum
static volatile int checksum
Definition: adler32.c:30
AV_AUDIO_SERVICE_TYPE_KARAOKE
@ AV_AUDIO_SERVICE_TYPE_KARAOKE
Definition: defs.h:66
SIZE_SPECIFIER
#define SIZE_SPECIFIER
Definition: internal.h:193
channel_layout.h
AV_MATRIX_ENCODING_DOLBYEX
@ AV_MATRIX_ENCODING_DOLBYEX
Definition: channel_layout.h:126
AV_AUDIO_SERVICE_TYPE_COMMENTARY
@ AV_AUDIO_SERVICE_TYPE_COMMENTARY
Definition: defs.h:63
AV_DOWNMIX_TYPE_DPLII
@ AV_DOWNMIX_TYPE_DPLII
Lt/Rt 2-channel downmix, Dolby Pro Logic II compatible.
Definition: downmix_info.h:48
avfilter.h
defs.h
AVReplayGain::album_peak
uint32_t album_peak
Same as track_peak, but for the whole album,.
Definition: replaygain.h:47
AVFrameSideData::type
enum AVFrameSideDataType type
Definition: frame.h:210
AVFilterContext
An instance of a filter.
Definition: avfilter.h:346
AVReplayGain
ReplayGain information (see http://wiki.hydrogenaudio.org/index.php?title=ReplayGain_1....
Definition: replaygain.h:29
mem.h
audio.h
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:209
AV_AUDIO_SERVICE_TYPE_EFFECTS
@ AV_AUDIO_SERVICE_TYPE_EFFECTS
Definition: defs.h:59
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:153
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AV_MATRIX_ENCODING_DPLIIZ
@ AV_MATRIX_ENCODING_DPLIIZ
Definition: channel_layout.h:125
int32_t
int32_t
Definition: audioconvert.c:56
convert_header.str
string str
Definition: convert_header.py:20
timestamp.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
av_ts2str
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: timestamp.h:54
AV_AUDIO_SERVICE_TYPE_DIALOGUE
@ AV_AUDIO_SERVICE_TYPE_DIALOGUE
Definition: defs.h:62
dump_replaygain
static void dump_replaygain(AVFilterContext *ctx, AVFrameSideData *sd)
Definition: af_ashowinfo.c:130
planar
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1<< 16)) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(UINT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out->ch+ch,(const uint8_t **) in->ch+ch, off *(out-> planar
Definition: audioconvert.c:56
AV_DOWNMIX_TYPE_LTRT
@ AV_DOWNMIX_TYPE_LTRT
Lt/Rt 2-channel downmix, Dolby Surround compatible.
Definition: downmix_info.h:47
AV_FRAME_DATA_DOWNMIX_INFO
@ AV_FRAME_DATA_DOWNMIX_INFO
Metadata relevant to a downmix procedure.
Definition: frame.h:72
AV_AUDIO_SERVICE_TYPE_MAIN
@ AV_AUDIO_SERVICE_TYPE_MAIN
Definition: defs.h:58
AV_MATRIX_ENCODING_DPLII
@ AV_MATRIX_ENCODING_DPLII
Definition: channel_layout.h:123