| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/pepper/content_decryptor_delegate.h" | 5 #include "content/renderer/pepper/content_decryptor_delegate.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
| (...skipping 1018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1029 DVLOG(2) << "DeliverSamples() - request_id: " << request_id; | 1029 DVLOG(2) << "DeliverSamples() - request_id: " << request_id; |
| 1030 | 1030 |
| 1031 // If the request ID is not valid or does not match what's saved, do nothing. | 1031 // If the request ID is not valid or does not match what's saved, do nothing. |
| 1032 if (request_id == 0 || !audio_decode_cb_.Matches(request_id)) { | 1032 if (request_id == 0 || !audio_decode_cb_.Matches(request_id)) { |
| 1033 DVLOG(1) << "DeliverSamples() - request_id " << request_id << " not found"; | 1033 DVLOG(1) << "DeliverSamples() - request_id " << request_id << " not found"; |
| 1034 return; | 1034 return; |
| 1035 } | 1035 } |
| 1036 | 1036 |
| 1037 Decryptor::AudioDecodeCB audio_decode_cb = audio_decode_cb_.ResetAndReturn(); | 1037 Decryptor::AudioDecodeCB audio_decode_cb = audio_decode_cb_.ResetAndReturn(); |
| 1038 | 1038 |
| 1039 const Decryptor::AudioBuffers empty_frames; | 1039 const Decryptor::AudioFrames empty_frames; |
| 1040 | 1040 |
| 1041 Decryptor::Status status = | 1041 Decryptor::Status status = |
| 1042 PpDecryptResultToMediaDecryptorStatus(sample_info->result); | 1042 PpDecryptResultToMediaDecryptorStatus(sample_info->result); |
| 1043 if (status != Decryptor::kSuccess) { | 1043 if (status != Decryptor::kSuccess) { |
| 1044 audio_decode_cb.Run(status, empty_frames); | 1044 audio_decode_cb.Run(status, empty_frames); |
| 1045 return; | 1045 return; |
| 1046 } | 1046 } |
| 1047 | 1047 |
| 1048 media::SampleFormat sample_format = | 1048 media::SampleFormat sample_format = |
| 1049 PpDecryptedSampleFormatToMediaSampleFormat(sample_info->format); | 1049 PpDecryptedSampleFormatToMediaSampleFormat(sample_info->format); |
| 1050 | 1050 |
| 1051 Decryptor::AudioBuffers audio_frame_list; | 1051 Decryptor::AudioFrames audio_frame_list; |
| 1052 if (!DeserializeAudioFrames(audio_frames, | 1052 if (!DeserializeAudioFrames(audio_frames, |
| 1053 sample_info->data_size, | 1053 sample_info->data_size, |
| 1054 sample_format, | 1054 sample_format, |
| 1055 &audio_frame_list)) { | 1055 &audio_frame_list)) { |
| 1056 NOTREACHED() << "CDM did not serialize the buffer correctly."; | 1056 NOTREACHED() << "CDM did not serialize the buffer correctly."; |
| 1057 audio_decode_cb.Run(Decryptor::kError, empty_frames); | 1057 audio_decode_cb.Run(Decryptor::kError, empty_frames); |
| 1058 return; | 1058 return; |
| 1059 } | 1059 } |
| 1060 | 1060 |
| 1061 audio_decode_cb.Run(Decryptor::kSuccess, audio_frame_list); | 1061 audio_decode_cb.Run(Decryptor::kSuccess, audio_frame_list); |
| 1062 } | 1062 } |
| 1063 | 1063 |
| 1064 // TODO(xhwang): Try to remove duplicate logic here and in CancelDecrypt(). | 1064 // TODO(xhwang): Try to remove duplicate logic here and in CancelDecrypt(). |
| 1065 void ContentDecryptorDelegate::CancelDecode(Decryptor::StreamType stream_type) { | 1065 void ContentDecryptorDelegate::CancelDecode(Decryptor::StreamType stream_type) { |
| 1066 switch (stream_type) { | 1066 switch (stream_type) { |
| 1067 case Decryptor::kAudio: | 1067 case Decryptor::kAudio: |
| 1068 // Release the shared memory as it can still be in use by the plugin. | 1068 // Release the shared memory as it can still be in use by the plugin. |
| 1069 // The next DecryptAndDecode() call will need to allocate a new shared | 1069 // The next DecryptAndDecode() call will need to allocate a new shared |
| 1070 // memory buffer. | 1070 // memory buffer. |
| 1071 audio_input_resource_ = NULL; | 1071 audio_input_resource_ = NULL; |
| 1072 if (!audio_decode_cb_.is_null()) | 1072 if (!audio_decode_cb_.is_null()) |
| 1073 audio_decode_cb_.ResetAndReturn().Run(Decryptor::kSuccess, | 1073 audio_decode_cb_.ResetAndReturn().Run(Decryptor::kSuccess, |
| 1074 Decryptor::AudioBuffers()); | 1074 Decryptor::AudioFrames()); |
| 1075 break; | 1075 break; |
| 1076 case Decryptor::kVideo: | 1076 case Decryptor::kVideo: |
| 1077 // Release the shared memory as it can still be in use by the plugin. | 1077 // Release the shared memory as it can still be in use by the plugin. |
| 1078 // The next DecryptAndDecode() call will need to allocate a new shared | 1078 // The next DecryptAndDecode() call will need to allocate a new shared |
| 1079 // memory buffer. | 1079 // memory buffer. |
| 1080 video_input_resource_ = NULL; | 1080 video_input_resource_ = NULL; |
| 1081 if (!video_decode_cb_.is_null()) | 1081 if (!video_decode_cb_.is_null()) |
| 1082 video_decode_cb_.ResetAndReturn().Run(Decryptor::kSuccess, NULL); | 1082 video_decode_cb_.ResetAndReturn().Run(Decryptor::kSuccess, NULL); |
| 1083 break; | 1083 break; |
| 1084 default: | 1084 default: |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1153 return; | 1153 return; |
| 1154 | 1154 |
| 1155 tracking_info->buffer_id = free_buffers_.front(); | 1155 tracking_info->buffer_id = free_buffers_.front(); |
| 1156 free_buffers_.pop(); | 1156 free_buffers_.pop(); |
| 1157 } | 1157 } |
| 1158 | 1158 |
| 1159 bool ContentDecryptorDelegate::DeserializeAudioFrames( | 1159 bool ContentDecryptorDelegate::DeserializeAudioFrames( |
| 1160 PP_Resource audio_frames, | 1160 PP_Resource audio_frames, |
| 1161 size_t data_size, | 1161 size_t data_size, |
| 1162 media::SampleFormat sample_format, | 1162 media::SampleFormat sample_format, |
| 1163 Decryptor::AudioBuffers* frames) { | 1163 Decryptor::AudioFrames* frames) { |
| 1164 DCHECK(frames); | 1164 DCHECK(frames); |
| 1165 EnterResourceNoLock<PPB_Buffer_API> enter(audio_frames, true); | 1165 EnterResourceNoLock<PPB_Buffer_API> enter(audio_frames, true); |
| 1166 if (!enter.succeeded()) | 1166 if (!enter.succeeded()) |
| 1167 return false; | 1167 return false; |
| 1168 | 1168 |
| 1169 BufferAutoMapper mapper(enter.object()); | 1169 BufferAutoMapper mapper(enter.object()); |
| 1170 if (!mapper.data() || !mapper.size() || | 1170 if (!mapper.data() || !mapper.size() || |
| 1171 mapper.size() < static_cast<uint32_t>(data_size)) | 1171 mapper.size() < static_cast<uint32_t>(data_size)) |
| 1172 return false; | 1172 return false; |
| 1173 | 1173 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 audio_input_resource_ = NULL; | 1242 audio_input_resource_ = NULL; |
| 1243 video_input_resource_ = NULL; | 1243 video_input_resource_ = NULL; |
| 1244 | 1244 |
| 1245 if (!audio_decrypt_cb_.is_null()) | 1245 if (!audio_decrypt_cb_.is_null()) |
| 1246 audio_decrypt_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); | 1246 audio_decrypt_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); |
| 1247 | 1247 |
| 1248 if (!video_decrypt_cb_.is_null()) | 1248 if (!video_decrypt_cb_.is_null()) |
| 1249 video_decrypt_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); | 1249 video_decrypt_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); |
| 1250 | 1250 |
| 1251 if (!audio_decode_cb_.is_null()) { | 1251 if (!audio_decode_cb_.is_null()) { |
| 1252 const media::Decryptor::AudioBuffers empty_frames; | 1252 const media::Decryptor::AudioFrames empty_frames; |
| 1253 audio_decode_cb_.ResetAndReturn().Run(media::Decryptor::kError, | 1253 audio_decode_cb_.ResetAndReturn().Run(media::Decryptor::kError, |
| 1254 empty_frames); | 1254 empty_frames); |
| 1255 } | 1255 } |
| 1256 | 1256 |
| 1257 if (!video_decode_cb_.is_null()) | 1257 if (!video_decode_cb_.is_null()) |
| 1258 video_decode_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); | 1258 video_decode_cb_.ResetAndReturn().Run(media::Decryptor::kError, NULL); |
| 1259 | 1259 |
| 1260 // Reject all outstanding promises. | 1260 // Reject all outstanding promises. |
| 1261 for (PromiseMap::iterator it = promises_.begin(); it != promises_.end(); | 1261 for (PromiseMap::iterator it = promises_.begin(); it != promises_.end(); |
| 1262 ++it) { | 1262 ++it) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1274 | 1274 |
| 1275 scoped_ptr<CdmPromise> ContentDecryptorDelegate::TakePromise( | 1275 scoped_ptr<CdmPromise> ContentDecryptorDelegate::TakePromise( |
| 1276 uint32_t promise_id) { | 1276 uint32_t promise_id) { |
| 1277 PromiseMap::iterator it = promises_.find(promise_id); | 1277 PromiseMap::iterator it = promises_.find(promise_id); |
| 1278 if (it == promises_.end()) | 1278 if (it == promises_.end()) |
| 1279 return scoped_ptr<CdmPromise>(); | 1279 return scoped_ptr<CdmPromise>(); |
| 1280 return promises_.take_and_erase(it); | 1280 return promises_.take_and_erase(it); |
| 1281 } | 1281 } |
| 1282 | 1282 |
| 1283 } // namespace content | 1283 } // namespace content |
| OLD | NEW |