| Index: services/media/framework_ffmpeg/ffmpeg_decoder.cc
|
| diff --git a/services/media/framework_ffmpeg/ffmpeg_decoder.cc b/services/media/framework_ffmpeg/ffmpeg_decoder.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f99dc5f90398bb7f14d1154b62bd0262ee6624ac
|
| --- /dev/null
|
| +++ b/services/media/framework_ffmpeg/ffmpeg_decoder.cc
|
| @@ -0,0 +1,50 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "services/media/framework_ffmpeg/ffmpeg_audio_decoder.h"
|
| +#include "services/media/framework_ffmpeg/ffmpeg_decoder.h"
|
| +#include "services/media/framework_ffmpeg/ffmpeg_type_converters.h"
|
| +#include "services/media/framework_ffmpeg/ffmpeg_video_decoder.h"
|
| +
|
| +namespace mojo {
|
| +namespace media {
|
| +
|
| +Result FfmpegDecoder::Create(
|
| + const StreamType& stream_type,
|
| + std::shared_ptr<Decoder>* decoder_out) {
|
| + DCHECK(decoder_out);
|
| +
|
| + AvCodecContextPtr av_codec_context(AVCodecContextFromStreamType(stream_type));
|
| + if (!av_codec_context) {
|
| + return Result::kUnsupportedOperation;
|
| + }
|
| +
|
| + AVCodec* ffmpeg_decoder = avcodec_find_decoder(av_codec_context->codec_id);
|
| + if (ffmpeg_decoder == nullptr) {
|
| + return Result::kUnsupportedOperation;
|
| + }
|
| +
|
| + int r = avcodec_open2(av_codec_context.get(), ffmpeg_decoder, nullptr);
|
| + if (r < 0) {
|
| + return Result::kUnknownError;
|
| + }
|
| +
|
| + switch (av_codec_context->codec_type) {
|
| + case AVMEDIA_TYPE_AUDIO:
|
| + *decoder_out = std::shared_ptr<Decoder>(
|
| + new FfmpegAudioDecoder(std::move(av_codec_context)));
|
| + break;
|
| + case AVMEDIA_TYPE_VIDEO:
|
| + *decoder_out = std::shared_ptr<Decoder>(
|
| + new FfmpegVideoDecoder(std::move(av_codec_context)));
|
| + break;
|
| + default:
|
| + return Result::kUnsupportedOperation;
|
| + }
|
| +
|
| + return Result::kOk;
|
| +}
|
| +
|
| +} // namespace media
|
| +} // namespace mojo
|
|
|