summaryrefslogtreecommitdiffstats
path: root/media/ffmpeg
diff options
context:
space:
mode:
Diffstat (limited to 'media/ffmpeg')
-rw-r--r--media/ffmpeg/ffmpeg_common.cc45
-rw-r--r--media/ffmpeg/ffmpeg_common.h7
2 files changed, 52 insertions, 0 deletions
diff --git a/media/ffmpeg/ffmpeg_common.cc b/media/ffmpeg/ffmpeg_common.cc
index 9f5eaeb..dedc40c 100644
--- a/media/ffmpeg/ffmpeg_common.cc
+++ b/media/ffmpeg/ffmpeg_common.cc
@@ -61,6 +61,51 @@ CodecID VideoCodecToCodecID(VideoCodec video_codec) {
return CODEC_ID_NONE;
}
+ChannelLayout ChannelLayoutToChromeChannelLayout(int64_t layout,
+ int channels) {
+ switch (layout) {
+ case CH_LAYOUT_MONO:
+ return CHANNEL_LAYOUT_MONO;
+ case CH_LAYOUT_STEREO:
+ return CHANNEL_LAYOUT_STEREO;
+ case CH_LAYOUT_2_1:
+ return CHANNEL_LAYOUT_2_1;
+ case CH_LAYOUT_SURROUND:
+ return CHANNEL_LAYOUT_SURROUND;
+ case CH_LAYOUT_4POINT0:
+ return CHANNEL_LAYOUT_4POINT0;
+ case CH_LAYOUT_2_2:
+ return CHANNEL_LAYOUT_2_2;
+ case CH_LAYOUT_QUAD:
+ return CHANNEL_LAYOUT_QUAD;
+ case CH_LAYOUT_5POINT0:
+ return CHANNEL_LAYOUT_5POINT0;
+ case CH_LAYOUT_5POINT1:
+ return CHANNEL_LAYOUT_5POINT1;
+ case CH_LAYOUT_5POINT0_BACK:
+ return CHANNEL_LAYOUT_5POINT0_BACK;
+ case CH_LAYOUT_5POINT1_BACK:
+ return CHANNEL_LAYOUT_5POINT1_BACK;
+ case CH_LAYOUT_7POINT0:
+ return CHANNEL_LAYOUT_7POINT0;
+ case CH_LAYOUT_7POINT1:
+ return CHANNEL_LAYOUT_7POINT1;
+ case CH_LAYOUT_7POINT1_WIDE:
+ return CHANNEL_LAYOUT_7POINT1_WIDE;
+ case CH_LAYOUT_STEREO_DOWNMIX:
+ return CHANNEL_LAYOUT_STEREO_DOWNMIX;
+ default:
+ // FFmpeg channel_layout is 0 for .wav and .mp3. We know mono and stereo
+ // from the number of channels, otherwise report errors.
+ if (channels == 1)
+ return CHANNEL_LAYOUT_MONO;
+ if (channels == 2)
+ return CHANNEL_LAYOUT_STEREO;
+ DLOG(WARNING) << "Unsupported/unencountered channel layout values";
+ return CHANNEL_LAYOUT_UNSUPPORTED;
+ }
+}
+
base::TimeDelta GetFrameDuration(AVStream* stream) {
AVRational time_base = { stream->r_frame_rate.den, stream->r_frame_rate.num };
return ConvertFromTimeBase(time_base, 1);
diff --git a/media/ffmpeg/ffmpeg_common.h b/media/ffmpeg/ffmpeg_common.h
index 196b57e..3d39d52 100644
--- a/media/ffmpeg/ffmpeg_common.h
+++ b/media/ffmpeg/ffmpeg_common.h
@@ -11,6 +11,7 @@
#include "base/compiler_specific.h"
#include "base/memory/singleton.h"
#include "base/time.h"
+#include "media/base/channel_layout.h"
#include "media/video/video_decode_engine.h"
// Include FFmpeg header files.
@@ -66,6 +67,12 @@ int64 ConvertToTimeBase(const AVRational& time_base,
VideoCodec CodecIDToVideoCodec(CodecID codec_id);
CodecID VideoCodecToCodecID(VideoCodec video_codec);
+// Converts FFmpeg's channel layout to chrome's ChannelLayout. |channels| can
+// be used when FFmpeg's channel layout is not informative in order to make a
+// good guess about the plausible channel layout based on number of channels.
+ChannelLayout ChannelLayoutToChromeChannelLayout(int64_t layout,
+ int channels);
+
// Calculates duration of one frame in the |stream| based on its frame rate.
base::TimeDelta GetFrameDuration(AVStream* stream);