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/ppb_video_decoder_impl.h" | 5 #include "content/renderer/pepper/ppb_video_decoder_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 using ppapi::thunk::PPB_Graphics3D_API; | 34 using ppapi::thunk::PPB_Graphics3D_API; |
35 using ppapi::thunk::PPB_VideoDecoder_API; | 35 using ppapi::thunk::PPB_VideoDecoder_API; |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 // Convert PP_VideoDecoder_Profile to media::VideoCodecProfile. | 39 // Convert PP_VideoDecoder_Profile to media::VideoCodecProfile. |
40 media::VideoCodecProfile PPToMediaProfile( | 40 media::VideoCodecProfile PPToMediaProfile( |
41 const PP_VideoDecoder_Profile pp_profile) { | 41 const PP_VideoDecoder_Profile pp_profile) { |
42 switch (pp_profile) { | 42 switch (pp_profile) { |
43 case PP_VIDEODECODER_H264PROFILE_NONE: | 43 case PP_VIDEODECODER_H264PROFILE_NONE: |
44 // HACK: PPAPI contains a bogus "none" h264 profile that doesn't | 44 // HACK: PPAPI contains a bogus "none" h264 profile that doesn't |
45 // correspond to anything in h.264; but a number of released chromium | 45 // correspond to anything in h.264; but a number of released chromium |
46 // versions silently promoted this to Baseline profile, so we retain that | 46 // versions silently promoted this to Baseline profile, so we retain that |
47 // behavior here. Fall through. | 47 // behavior here. Fall through. |
48 case PP_VIDEODECODER_H264PROFILE_BASELINE: | 48 case PP_VIDEODECODER_H264PROFILE_BASELINE: |
49 return media::H264PROFILE_BASELINE; | 49 return media::H264PROFILE_BASELINE; |
50 case PP_VIDEODECODER_H264PROFILE_MAIN: | 50 case PP_VIDEODECODER_H264PROFILE_MAIN: |
51 return media::H264PROFILE_MAIN; | 51 return media::H264PROFILE_MAIN; |
52 case PP_VIDEODECODER_H264PROFILE_EXTENDED: | 52 case PP_VIDEODECODER_H264PROFILE_EXTENDED: |
53 return media::H264PROFILE_EXTENDED; | 53 return media::H264PROFILE_EXTENDED; |
54 case PP_VIDEODECODER_H264PROFILE_HIGH: | 54 case PP_VIDEODECODER_H264PROFILE_HIGH: |
55 return media::H264PROFILE_HIGH; | 55 return media::H264PROFILE_HIGH; |
56 case PP_VIDEODECODER_H264PROFILE_HIGH10PROFILE: | 56 case PP_VIDEODECODER_H264PROFILE_HIGH10PROFILE: |
57 return media::H264PROFILE_HIGH10PROFILE; | 57 return media::H264PROFILE_HIGH10PROFILE; |
(...skipping 12 matching lines...) Expand all Loading... |
70 case PP_VIDEODECODER_VP8PROFILE_MAIN: | 70 case PP_VIDEODECODER_VP8PROFILE_MAIN: |
71 return media::VP8PROFILE_MAIN; | 71 return media::VP8PROFILE_MAIN; |
72 default: | 72 default: |
73 return media::VIDEO_CODEC_PROFILE_UNKNOWN; | 73 return media::VIDEO_CODEC_PROFILE_UNKNOWN; |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 PP_VideoDecodeError_Dev MediaToPPError( | 77 PP_VideoDecodeError_Dev MediaToPPError( |
78 media::VideoDecodeAccelerator::Error error) { | 78 media::VideoDecodeAccelerator::Error error) { |
79 switch (error) { | 79 switch (error) { |
80 case media::VideoDecodeAccelerator::ILLEGAL_STATE : | 80 case media::VideoDecodeAccelerator::ILLEGAL_STATE: |
81 return PP_VIDEODECODERERROR_ILLEGAL_STATE; | 81 return PP_VIDEODECODERERROR_ILLEGAL_STATE; |
82 case media::VideoDecodeAccelerator::INVALID_ARGUMENT : | 82 case media::VideoDecodeAccelerator::INVALID_ARGUMENT: |
83 return PP_VIDEODECODERERROR_INVALID_ARGUMENT; | 83 return PP_VIDEODECODERERROR_INVALID_ARGUMENT; |
84 case media::VideoDecodeAccelerator::UNREADABLE_INPUT : | 84 case media::VideoDecodeAccelerator::UNREADABLE_INPUT: |
85 return PP_VIDEODECODERERROR_UNREADABLE_INPUT; | 85 return PP_VIDEODECODERERROR_UNREADABLE_INPUT; |
86 case media::VideoDecodeAccelerator::PLATFORM_FAILURE : | 86 case media::VideoDecodeAccelerator::PLATFORM_FAILURE: |
87 return PP_VIDEODECODERERROR_PLATFORM_FAILURE; | 87 return PP_VIDEODECODERERROR_PLATFORM_FAILURE; |
88 default: | 88 default: |
89 NOTREACHED(); | 89 NOTREACHED(); |
90 return PP_VIDEODECODERERROR_ILLEGAL_STATE; | 90 return PP_VIDEODECODERERROR_ILLEGAL_STATE; |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
94 } // namespace | 94 } // namespace |
95 | 95 |
96 namespace content { | 96 namespace content { |
97 | 97 |
98 PPB_VideoDecoder_Impl::PPB_VideoDecoder_Impl(PP_Instance instance) | 98 PPB_VideoDecoder_Impl::PPB_VideoDecoder_Impl(PP_Instance instance) |
99 : PPB_VideoDecoder_Shared(instance), | 99 : PPB_VideoDecoder_Shared(instance), ppp_videodecoder_(NULL) { |
100 ppp_videodecoder_(NULL) { | |
101 PluginModule* plugin_module = | 100 PluginModule* plugin_module = |
102 HostGlobals::Get()->GetInstance(pp_instance())->module(); | 101 HostGlobals::Get()->GetInstance(pp_instance())->module(); |
103 if (plugin_module) { | 102 if (plugin_module) { |
104 ppp_videodecoder_ = static_cast<const PPP_VideoDecoder_Dev*>( | 103 ppp_videodecoder_ = static_cast<const PPP_VideoDecoder_Dev*>( |
105 plugin_module->GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE)); | 104 plugin_module->GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE)); |
106 } | 105 } |
107 } | 106 } |
108 | 107 |
109 PPB_VideoDecoder_Impl::~PPB_VideoDecoder_Impl() { | 108 PPB_VideoDecoder_Impl::~PPB_VideoDecoder_Impl() { Destroy(); } |
110 Destroy(); | |
111 } | |
112 | 109 |
113 // static | 110 // static |
114 PP_Resource PPB_VideoDecoder_Impl::Create( | 111 PP_Resource PPB_VideoDecoder_Impl::Create(PP_Instance instance, |
115 PP_Instance instance, | 112 PP_Resource graphics_context, |
116 PP_Resource graphics_context, | 113 PP_VideoDecoder_Profile profile) { |
117 PP_VideoDecoder_Profile profile) { | |
118 EnterResourceNoLock<PPB_Graphics3D_API> enter_context(graphics_context, true); | 114 EnterResourceNoLock<PPB_Graphics3D_API> enter_context(graphics_context, true); |
119 if (enter_context.failed()) | 115 if (enter_context.failed()) |
120 return 0; | 116 return 0; |
121 PPB_Graphics3D_Impl* graphics3d_impl = | 117 PPB_Graphics3D_Impl* graphics3d_impl = |
122 static_cast<PPB_Graphics3D_Impl*>(enter_context.object()); | 118 static_cast<PPB_Graphics3D_Impl*>(enter_context.object()); |
123 | 119 |
124 scoped_refptr<PPB_VideoDecoder_Impl> decoder( | 120 scoped_refptr<PPB_VideoDecoder_Impl> decoder( |
125 new PPB_VideoDecoder_Impl(instance)); | 121 new PPB_VideoDecoder_Impl(instance)); |
126 if (decoder->Init(graphics_context, graphics3d_impl->platform_context(), | 122 if (decoder->Init(graphics_context, |
127 graphics3d_impl->gles2_impl(), profile)) | 123 graphics3d_impl->platform_context(), |
| 124 graphics3d_impl->gles2_impl(), |
| 125 profile)) |
128 return decoder->GetReference(); | 126 return decoder->GetReference(); |
129 return 0; | 127 return 0; |
130 } | 128 } |
131 | 129 |
132 bool PPB_VideoDecoder_Impl::Init( | 130 bool PPB_VideoDecoder_Impl::Init(PP_Resource graphics_context, |
133 PP_Resource graphics_context, | 131 PlatformContext3D* context, |
134 PlatformContext3D* context, | 132 gpu::gles2::GLES2Implementation* gles2_impl, |
135 gpu::gles2::GLES2Implementation* gles2_impl, | 133 PP_VideoDecoder_Profile profile) { |
136 PP_VideoDecoder_Profile profile) { | |
137 InitCommon(graphics_context, gles2_impl); | 134 InitCommon(graphics_context, gles2_impl); |
138 | 135 |
139 int command_buffer_route_id = context->GetCommandBufferRouteId(); | 136 int command_buffer_route_id = context->GetCommandBufferRouteId(); |
140 if (command_buffer_route_id == 0) | 137 if (command_buffer_route_id == 0) |
141 return false; | 138 return false; |
142 | 139 |
143 platform_video_decoder_.reset( | 140 platform_video_decoder_.reset( |
144 new PlatformVideoDecoder(command_buffer_route_id)); | 141 new PlatformVideoDecoder(command_buffer_route_id)); |
145 if (!platform_video_decoder_) | 142 if (!platform_video_decoder_) |
146 return false; | 143 return false; |
147 | 144 |
148 FlushCommandBuffer(); | 145 FlushCommandBuffer(); |
149 return platform_video_decoder_->Initialize(PPToMediaProfile(profile), this); | 146 return platform_video_decoder_->Initialize(PPToMediaProfile(profile), this); |
150 } | 147 } |
151 | 148 |
152 int32_t PPB_VideoDecoder_Impl::Decode( | 149 int32_t PPB_VideoDecoder_Impl::Decode( |
153 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, | 150 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, |
154 scoped_refptr<TrackedCallback> callback) { | 151 scoped_refptr<TrackedCallback> callback) { |
155 if (!platform_video_decoder_) | 152 if (!platform_video_decoder_) |
156 return PP_ERROR_BADRESOURCE; | 153 return PP_ERROR_BADRESOURCE; |
157 | 154 |
158 EnterResourceNoLock<PPB_Buffer_API> enter(bitstream_buffer->data, true); | 155 EnterResourceNoLock<PPB_Buffer_API> enter(bitstream_buffer->data, true); |
159 if (enter.failed()) | 156 if (enter.failed()) |
160 return PP_ERROR_FAILED; | 157 return PP_ERROR_FAILED; |
161 | 158 |
162 PPB_Buffer_Impl* buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); | 159 PPB_Buffer_Impl* buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); |
163 DCHECK_GE(bitstream_buffer->id, 0); | 160 DCHECK_GE(bitstream_buffer->id, 0); |
164 media::BitstreamBuffer decode_buffer( | 161 media::BitstreamBuffer decode_buffer(bitstream_buffer->id, |
165 bitstream_buffer->id, | 162 buffer->shared_memory()->handle(), |
166 buffer->shared_memory()->handle(), | 163 bitstream_buffer->size); |
167 bitstream_buffer->size); | |
168 if (!SetBitstreamBufferCallback(bitstream_buffer->id, callback)) | 164 if (!SetBitstreamBufferCallback(bitstream_buffer->id, callback)) |
169 return PP_ERROR_BADARGUMENT; | 165 return PP_ERROR_BADARGUMENT; |
170 | 166 |
171 FlushCommandBuffer(); | 167 FlushCommandBuffer(); |
172 platform_video_decoder_->Decode(decode_buffer); | 168 platform_video_decoder_->Decode(decode_buffer); |
173 return PP_OK_COMPLETIONPENDING; | 169 return PP_OK_COMPLETIONPENDING; |
174 } | 170 } |
175 | 171 |
176 void PPB_VideoDecoder_Impl::AssignPictureBuffers( | 172 void PPB_VideoDecoder_Impl::AssignPictureBuffers( |
177 uint32_t no_of_buffers, | 173 uint32_t no_of_buffers, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 } | 237 } |
242 | 238 |
243 void PPB_VideoDecoder_Impl::ProvidePictureBuffers( | 239 void PPB_VideoDecoder_Impl::ProvidePictureBuffers( |
244 uint32 requested_num_of_buffers, | 240 uint32 requested_num_of_buffers, |
245 const gfx::Size& dimensions, | 241 const gfx::Size& dimensions, |
246 uint32 texture_target) { | 242 uint32 texture_target) { |
247 if (!ppp_videodecoder_) | 243 if (!ppp_videodecoder_) |
248 return; | 244 return; |
249 | 245 |
250 PP_Size out_dim = PP_MakeSize(dimensions.width(), dimensions.height()); | 246 PP_Size out_dim = PP_MakeSize(dimensions.width(), dimensions.height()); |
251 ppp_videodecoder_->ProvidePictureBuffers(pp_instance(), pp_resource(), | 247 ppp_videodecoder_->ProvidePictureBuffers(pp_instance(), |
252 requested_num_of_buffers, &out_dim, texture_target); | 248 pp_resource(), |
| 249 requested_num_of_buffers, |
| 250 &out_dim, |
| 251 texture_target); |
253 } | 252 } |
254 | 253 |
255 void PPB_VideoDecoder_Impl::PictureReady(const media::Picture& picture) { | 254 void PPB_VideoDecoder_Impl::PictureReady(const media::Picture& picture) { |
256 if (!ppp_videodecoder_) | 255 if (!ppp_videodecoder_) |
257 return; | 256 return; |
258 | 257 |
259 PP_Picture_Dev output; | 258 PP_Picture_Dev output; |
260 output.picture_buffer_id = picture.picture_buffer_id(); | 259 output.picture_buffer_id = picture.picture_buffer_id(); |
261 output.bitstream_buffer_id = picture.bitstream_buffer_id(); | 260 output.bitstream_buffer_id = picture.bitstream_buffer_id(); |
262 ppp_videodecoder_->PictureReady(pp_instance(), pp_resource(), &output); | 261 ppp_videodecoder_->PictureReady(pp_instance(), pp_resource(), &output); |
263 } | 262 } |
264 | 263 |
265 void PPB_VideoDecoder_Impl::DismissPictureBuffer(int32 picture_buffer_id) { | 264 void PPB_VideoDecoder_Impl::DismissPictureBuffer(int32 picture_buffer_id) { |
266 if (!ppp_videodecoder_) | 265 if (!ppp_videodecoder_) |
267 return; | 266 return; |
268 ppp_videodecoder_->DismissPictureBuffer(pp_instance(), pp_resource(), | 267 ppp_videodecoder_->DismissPictureBuffer( |
269 picture_buffer_id); | 268 pp_instance(), pp_resource(), picture_buffer_id); |
270 } | 269 } |
271 | 270 |
272 void PPB_VideoDecoder_Impl::NotifyError( | 271 void PPB_VideoDecoder_Impl::NotifyError( |
273 media::VideoDecodeAccelerator::Error error) { | 272 media::VideoDecodeAccelerator::Error error) { |
274 if (!ppp_videodecoder_) | 273 if (!ppp_videodecoder_) |
275 return; | 274 return; |
276 | 275 |
277 PP_VideoDecodeError_Dev pp_error = MediaToPPError(error); | 276 PP_VideoDecodeError_Dev pp_error = MediaToPPError(error); |
278 ppp_videodecoder_->NotifyError(pp_instance(), pp_resource(), pp_error); | 277 ppp_videodecoder_->NotifyError(pp_instance(), pp_resource(), pp_error); |
279 UMA_HISTOGRAM_ENUMERATION( | 278 UMA_HISTOGRAM_ENUMERATION("Media.PepperVideoDecoderError", |
280 "Media.PepperVideoDecoderError", error, | 279 error, |
281 media::VideoDecodeAccelerator::LARGEST_ERROR_ENUM); | 280 media::VideoDecodeAccelerator::LARGEST_ERROR_ENUM); |
282 } | 281 } |
283 | 282 |
284 void PPB_VideoDecoder_Impl::NotifyResetDone() { | 283 void PPB_VideoDecoder_Impl::NotifyResetDone() { RunResetCallback(PP_OK); } |
285 RunResetCallback(PP_OK); | |
286 } | |
287 | 284 |
288 void PPB_VideoDecoder_Impl::NotifyEndOfBitstreamBuffer( | 285 void PPB_VideoDecoder_Impl::NotifyEndOfBitstreamBuffer( |
289 int32 bitstream_buffer_id) { | 286 int32 bitstream_buffer_id) { |
290 RunBitstreamBufferCallback(bitstream_buffer_id, PP_OK); | 287 RunBitstreamBufferCallback(bitstream_buffer_id, PP_OK); |
291 } | 288 } |
292 | 289 |
293 void PPB_VideoDecoder_Impl::NotifyFlushDone() { | 290 void PPB_VideoDecoder_Impl::NotifyFlushDone() { RunFlushCallback(PP_OK); } |
294 RunFlushCallback(PP_OK); | |
295 } | |
296 | 291 |
297 } // namespace content | 292 } // namespace content |
OLD | NEW |