1 // Copyright 2014 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 "media/filters/decoder_stream_traits.h" 6 7 #include "base/logging.h" 8 #include "media/base/audio_buffer.h" 9 #include "media/base/audio_decoder.h" 10 #include "media/base/audio_decoder_config.h" 11 #include "media/base/video_decoder.h" 12 #include "media/base/video_decoder_config.h" 13 #include "media/base/video_frame.h" 14 15 namespace media { 16 17 std::string DecoderStreamTraits<DemuxerStream::AUDIO>::ToString() { 18 return "Audio"; 19 } 20 21 void DecoderStreamTraits<DemuxerStream::AUDIO>::Initialize( 22 DecoderType* decoder, 23 const DecoderConfigType& config, 24 bool low_delay, 25 const PipelineStatusCB& status_cb, 26 const OutputCB& output_cb) { 27 decoder->Initialize(config, status_cb, output_cb); 28 } 29 30 bool DecoderStreamTraits<DemuxerStream::AUDIO>::FinishInitialization( 31 const StreamInitCB& init_cb, 32 DecoderType* decoder, 33 DemuxerStream* stream) { 34 DCHECK(stream); 35 if (!decoder) { 36 init_cb.Run(false); 37 return false; 38 } 39 init_cb.Run(true); 40 return true; 41 } 42 43 void DecoderStreamTraits<DemuxerStream::AUDIO>::ReportStatistics( 44 const StatisticsCB& statistics_cb, 45 int bytes_decoded) { 46 PipelineStatistics statistics; 47 statistics.audio_bytes_decoded = bytes_decoded; 48 statistics_cb.Run(statistics); 49 } 50 51 DecoderStreamTraits<DemuxerStream::AUDIO>::DecoderConfigType 52 DecoderStreamTraits<DemuxerStream::AUDIO>::GetDecoderConfig( 53 DemuxerStream& stream) { 54 return stream.audio_decoder_config(); 55 } 56 57 scoped_refptr<DecoderStreamTraits<DemuxerStream::AUDIO>::OutputType> 58 DecoderStreamTraits<DemuxerStream::AUDIO>::CreateEOSOutput() { 59 return OutputType::CreateEOSBuffer(); 60 } 61 62 std::string DecoderStreamTraits<DemuxerStream::VIDEO>::ToString() { 63 return "Video"; 64 } 65 66 void DecoderStreamTraits<DemuxerStream::VIDEO>::Initialize( 67 DecoderType* decoder, 68 const DecoderConfigType& config, 69 bool low_delay, 70 const PipelineStatusCB& status_cb, 71 const OutputCB& output_cb) { 72 decoder->Initialize(config, low_delay, status_cb, output_cb); 73 } 74 75 bool DecoderStreamTraits<DemuxerStream::VIDEO>::FinishInitialization( 76 const StreamInitCB& init_cb, 77 DecoderType* decoder, 78 DemuxerStream* stream) { 79 DCHECK(stream); 80 if (!decoder) { 81 init_cb.Run(false); 82 return false; 83 } 84 if (decoder->NeedsBitstreamConversion()) 85 stream->EnableBitstreamConverter(); 86 init_cb.Run(true); 87 return true; 88 } 89 90 void DecoderStreamTraits<DemuxerStream::VIDEO>::ReportStatistics( 91 const StatisticsCB& statistics_cb, 92 int bytes_decoded) { 93 PipelineStatistics statistics; 94 statistics.video_bytes_decoded = bytes_decoded; 95 statistics_cb.Run(statistics); 96 } 97 98 DecoderStreamTraits<DemuxerStream::VIDEO>::DecoderConfigType 99 DecoderStreamTraits<DemuxerStream::VIDEO>::GetDecoderConfig( 100 DemuxerStream& stream) { 101 return stream.video_decoder_config(); 102 } 103 104 scoped_refptr<DecoderStreamTraits<DemuxerStream::VIDEO>::OutputType> 105 DecoderStreamTraits<DemuxerStream::VIDEO>::CreateEOSOutput() { 106 return OutputType::CreateEOSFrame(); 107 } 108 109 } // namespace media 110