summaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorVittorio Giovara <vittorio.giovara@gmail.com>2017-04-25 16:26:58 -0400
committerVittorio Giovara <vittorio.giovara@gmail.com>2017-04-26 11:21:27 -0400
commit94c54d97e7f4fe90570c323803f2bdf6246c1010 (patch)
tree65a8e2410efa07825bae843e71cefcbb18a54047 /libavcodec
parentcea7fd9afb8488a6c48f7d7ee38602e1fd3dd425 (diff)
downloadffmpeg-streaming-94c54d97e7f4fe90570c323803f2bdf6246c1010.zip
ffmpeg-streaming-94c54d97e7f4fe90570c323803f2bdf6246c1010.tar.gz
mlp: Factor out channel layout subset checks
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/mlp_parser.c22
-rw-r--r--libavcodec/mlp_parser.h2
-rw-r--r--libavcodec/mlpdec.c4
3 files changed, 15 insertions, 13 deletions
diff --git a/libavcodec/mlp_parser.c b/libavcodec/mlp_parser.c
index fb9ede8..7d73058 100644
--- a/libavcodec/mlp_parser.c
+++ b/libavcodec/mlp_parser.c
@@ -120,6 +120,11 @@ static uint64_t truehd_layout(int chanmap)
return layout;
}
+int ff_mlp_channel_layout_subset(uint64_t channel_layout, uint64_t mask)
+{
+ return channel_layout && ((channel_layout & mask) == channel_layout);
+}
+
static int mlp_get_major_sync_size(const uint8_t * buf, int bufsize)
{
int has_extension, extensions = 0;
@@ -331,6 +336,8 @@ static int mlp_parse(AVCodecParserContext *s,
} else {
BitstreamContext bc;
MLPHeaderInfo mh;
+ int stereo_requested = ff_mlp_channel_layout_subset(avctx->request_channel_layout,
+ AV_CH_LAYOUT_STEREO);
bitstream_init8(&bc, buf + 4, buf_size - 4);
if (ff_mlp_read_major_sync(avctx, &mh, &bc) < 0)
@@ -346,10 +353,7 @@ static int mlp_parse(AVCodecParserContext *s,
if (mh.stream_type == 0xbb) {
/* MLP stream */
- if (avctx->request_channel_layout &&
- (avctx->request_channel_layout & AV_CH_LAYOUT_STEREO) ==
- avctx->request_channel_layout &&
- mh.num_substreams > 1) {
+ if (stereo_requested && mh.num_substreams > 1) {
avctx->channels = 2;
avctx->channel_layout = AV_CH_LAYOUT_STEREO;
} else {
@@ -358,16 +362,12 @@ static int mlp_parse(AVCodecParserContext *s,
}
} else { /* mh.stream_type == 0xba */
/* TrueHD stream */
- if (avctx->request_channel_layout &&
- (avctx->request_channel_layout & AV_CH_LAYOUT_STEREO) ==
- avctx->request_channel_layout &&
- mh.num_substreams > 1) {
+ if (stereo_requested && mh.num_substreams > 1) {
avctx->channels = 2;
avctx->channel_layout = AV_CH_LAYOUT_STEREO;
} else if (!mh.channels_thd_stream2 ||
- (avctx->request_channel_layout &&
- (avctx->request_channel_layout & mh.channel_layout_thd_stream1) ==
- avctx->request_channel_layout)) {
+ ff_mlp_channel_layout_subset(avctx->request_channel_layout,
+ mh.channel_layout_thd_stream1)) {
avctx->channels = mh.channels_thd_stream1;
avctx->channel_layout = mh.channel_layout_thd_stream1;
} else {
diff --git a/libavcodec/mlp_parser.h b/libavcodec/mlp_parser.h
index 871b96d..946f4d2 100644
--- a/libavcodec/mlp_parser.h
+++ b/libavcodec/mlp_parser.h
@@ -63,4 +63,6 @@ typedef struct MLPHeaderInfo
int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, BitstreamContext *bc);
+int ff_mlp_channel_layout_subset(uint64_t channel_layout, uint64_t mask);
+
#endif /* AVCODEC_MLP_PARSER_H */
diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
index 9ce32c8..fa94f6f 100644
--- a/libavcodec/mlpdec.c
+++ b/libavcodec/mlpdec.c
@@ -511,8 +511,8 @@ static int read_restart_header(MLPDecodeContext *m, BitstreamContext *bc,
s->max_channel = max_channel;
s->max_matrix_channel = max_matrix_channel;
- if (m->avctx->request_channel_layout && (s->mask & m->avctx->request_channel_layout) ==
- m->avctx->request_channel_layout && m->max_decoded_substream > substr) {
+ if (ff_mlp_channel_layout_subset(m->avctx->request_channel_layout, s->mask) &&
+ m->max_decoded_substream > substr) {
av_log(m->avctx, AV_LOG_DEBUG,
"Extracting %d-channel downmix (0x%"PRIx64") from substream %d. "
"Further substreams will be skipped.\n",
OpenPOWER on IntegriCloud