OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/mojo/services/mojo_audio_decoder_service.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/bind_helpers.h" | |
5 #include "base/logging.h" | 9 #include "base/logging.h" |
6 #include "media/mojo/services/mojo_audio_decoder_service.h" | 10 #include "media/base/cdm_context.h" |
11 #include "media/mojo/common/media_type_converters.h" | |
7 | 12 |
8 namespace media { | 13 namespace media { |
9 | 14 |
10 MojoAudioDecoderService::MojoAudioDecoderService( | 15 MojoAudioDecoderService::MojoAudioDecoderService( |
11 scoped_ptr<media::AudioDecoder> decoder, | 16 scoped_ptr<media::AudioDecoder> decoder, |
12 mojo::InterfaceRequest<interfaces::AudioDecoder> request) | 17 mojo::InterfaceRequest<interfaces::AudioDecoder> request) |
13 : binding_(this, std::move(request)), decoder_(std::move(decoder)) {} | 18 : binding_(this, std::move(request)), decoder_(std::move(decoder)) {} |
14 | 19 |
15 MojoAudioDecoderService::~MojoAudioDecoderService() {} | 20 MojoAudioDecoderService::~MojoAudioDecoderService() {} |
16 | 21 |
17 void MojoAudioDecoderService::Initialize( | 22 void MojoAudioDecoderService::Initialize( |
18 interfaces::AudioDecoderClientPtr client, | 23 interfaces::AudioDecoderClientPtr client, |
19 interfaces::AudioDecoderConfigPtr config, | 24 interfaces::AudioDecoderConfigPtr config, |
20 int32_t cdm_id, | 25 int32_t cdm_id, |
21 const InitializeCallback& callback) { | 26 const InitializeCallback& callback) { |
22 NOTIMPLEMENTED(); | 27 DVLOG(1) << __FUNCTION__ << " " |
23 callback.Run(false, false); | 28 << config.To<media::AudioDecoderConfig>().AsHumanReadableString(); |
29 | |
30 // Encrypted streams are not supported for now. | |
31 if (config.To<media::AudioDecoderConfig>().is_encrypted() && | |
32 cdm_id == CdmContext::kInvalidCdmId) { | |
33 LOG(ERROR) << "AudioDecoderService: encrypted streams are not supported"; | |
xhwang
2016/03/18 23:01:13
s/LOG(ERROR)/NOTREACHED()/
This should never happ
Tima Vaisburd
2016/03/19 03:09:05
Done.
| |
34 callback.Run(false, false); | |
35 return; | |
36 } | |
37 | |
38 client_ = std::move(client); | |
39 | |
40 DCHECK(initialize_callback_.is_null()); | |
41 initialize_callback_ = callback; | |
xhwang
2016/03/18 23:01:13
You can also bind |callback| in OnInitialized(). S
Tima Vaisburd
2016/03/19 03:09:05
Done. This seems possible for the client side (i.e
| |
42 | |
43 decoder_->Initialize(config.To<media::AudioDecoderConfig>(), | |
xhwang
2016/03/18 23:01:13
Add a TODO to get CdmContext from cdm_id.
Tima Vaisburd
2016/03/19 03:09:05
Done.
| |
44 nullptr, // no CdmContext | |
45 base::Bind(&MojoAudioDecoderService::OnInitialized, | |
46 base::Unretained(this)), | |
xhwang
2016/03/18 23:01:13
base::Unretained() is not safe. You need weak poin
Tima Vaisburd
2016/03/19 03:09:05
Done.
| |
47 base::Bind(&MojoAudioDecoderService::OnAudioBufferReady, | |
48 base::Unretained(this))); | |
24 } | 49 } |
25 | 50 |
26 void MojoAudioDecoderService::Decode(interfaces::DecoderBufferPtr buffer, | 51 void MojoAudioDecoderService::Decode(interfaces::DecoderBufferPtr buffer, |
27 const DecodeCallback& callback) { | 52 const DecodeCallback& callback) { |
28 NOTIMPLEMENTED(); | 53 DVLOG(3) << __FUNCTION__; |
29 callback.Run(DecodeStatus::DECODE_ERROR); | 54 |
55 DCHECK(decode_callback_.is_null()); | |
56 decode_callback_ = callback; | |
57 decoder_->Decode(ReadDecoderBuffer(std::move(buffer)), | |
58 base::Bind(&MojoAudioDecoderService::OnDecodeStatus, | |
59 base::Unretained(this))); | |
30 } | 60 } |
31 | 61 |
32 void MojoAudioDecoderService::Reset(const ResetCallback& callback) { | 62 void MojoAudioDecoderService::Reset(const ResetCallback& callback) { |
63 DVLOG(1) << __FUNCTION__; | |
64 | |
65 DCHECK(reset_callback_.is_null()); | |
66 reset_callback_ = callback; | |
67 decoder_->Reset(base::Bind(&MojoAudioDecoderService::OnResetDone, | |
68 base::Unretained(this))); | |
69 } | |
70 | |
71 void MojoAudioDecoderService::OnInitialized(bool success) { | |
72 DVLOG(1) << __FUNCTION__ << " success:" << success; | |
73 | |
74 initialize_callback_.Run(success, decoder_->NeedsBitstreamConversion()); | |
75 initialize_callback_.reset(); | |
76 } | |
77 | |
78 static interfaces::AudioDecoder::DecodeStatus ConvertDecodeStatus( | |
79 media::AudioDecoder::Status status) { | |
80 switch (status) { | |
81 case media::AudioDecoder::kOk: | |
82 return interfaces::AudioDecoder::DecodeStatus::OK; | |
83 case media::AudioDecoder::kAborted: | |
84 return interfaces::AudioDecoder::DecodeStatus::ABORTED; | |
85 case media::AudioDecoder::kDecodeError: | |
86 return interfaces::AudioDecoder::DecodeStatus::DECODE_ERROR; | |
87 } | |
88 NOTREACHED(); | |
89 return interfaces::AudioDecoder::DecodeStatus::DECODE_ERROR; | |
90 } | |
91 | |
92 void MojoAudioDecoderService::OnDecodeStatus( | |
93 media::AudioDecoder::Status status) { | |
94 DVLOG(3) << __FUNCTION__ << " status:" << status; | |
95 | |
96 decode_callback_.Run(ConvertDecodeStatus(status)); | |
97 decode_callback_.reset(); | |
98 } | |
99 | |
100 void MojoAudioDecoderService::OnResetDone() { | |
101 DVLOG(1) << __FUNCTION__; | |
102 | |
103 // There should be no pending decode operation. | |
104 DCHECK(decode_callback_.is_null()); | |
105 | |
106 reset_callback_.Run(); | |
107 reset_callback_.reset(); | |
108 } | |
109 | |
110 void MojoAudioDecoderService::OnAudioBufferReady( | |
111 const scoped_refptr<AudioBuffer>& audio_buffer) { | |
112 DVLOG(1) << __FUNCTION__; | |
33 NOTIMPLEMENTED(); | 113 NOTIMPLEMENTED(); |
34 callback.Run(); | 114 } |
115 | |
116 scoped_refptr<DecoderBuffer> MojoAudioDecoderService::ReadDecoderBuffer( | |
117 interfaces::DecoderBufferPtr buffer) { | |
118 scoped_refptr<DecoderBuffer> media_buffer( | |
119 buffer.To<scoped_refptr<DecoderBuffer>>()); | |
120 | |
121 NOTIMPLEMENTED(); | |
122 return media_buffer; | |
35 } | 123 } |
36 | 124 |
37 } // namespace media | 125 } // namespace media |
OLD | NEW |