OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "services/media/framework_ffmpeg/ffmpeg_audio_decoder.h" |
| 6 #include "services/media/framework_ffmpeg/ffmpeg_decoder.h" |
| 7 #include "services/media/framework_ffmpeg/ffmpeg_type_converters.h" |
| 8 #include "services/media/framework_ffmpeg/ffmpeg_video_decoder.h" |
| 9 |
| 10 namespace mojo { |
| 11 namespace media { |
| 12 |
| 13 Result FfmpegDecoder::Create( |
| 14 const StreamType& stream_type, |
| 15 std::shared_ptr<Decoder>* decoder_out) { |
| 16 DCHECK(decoder_out); |
| 17 |
| 18 AVCodecContext* av_codec_context = AVCodecContextFromStreamType(stream_type); |
| 19 if (av_codec_context == nullptr) { |
| 20 return Result::kUnsupportedOperation; |
| 21 } |
| 22 |
| 23 AVCodec* ffmpeg_decoder = avcodec_find_decoder(av_codec_context->codec_id); |
| 24 if (ffmpeg_decoder == nullptr) { |
| 25 avcodec_free_context(&av_codec_context); |
| 26 return Result::kUnsupportedOperation; |
| 27 } |
| 28 |
| 29 int r = avcodec_open2(av_codec_context, ffmpeg_decoder, nullptr); |
| 30 if (r < 0) { |
| 31 avcodec_free_context(&av_codec_context); |
| 32 return Result::kUnknownError; |
| 33 } |
| 34 |
| 35 switch (av_codec_context->codec_type) { |
| 36 case AVMEDIA_TYPE_AUDIO: |
| 37 *decoder_out = |
| 38 std::shared_ptr<Decoder>(new FfmpegAudioDecoder(av_codec_context)); |
| 39 break; |
| 40 case AVMEDIA_TYPE_VIDEO: |
| 41 *decoder_out = |
| 42 std::shared_ptr<Decoder>(new FfmpegVideoDecoder(av_codec_context)); |
| 43 break; |
| 44 default: |
| 45 avcodec_free_context(&av_codec_context); |
| 46 return Result::kUnsupportedOperation; |
| 47 } |
| 48 |
| 49 return Result::kOk; |
| 50 } |
| 51 |
| 52 } // namespace media |
| 53 } // namespace mojo |
OLD | NEW |