OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/glue/plugins/pepper_video_decoder.h" | 5 #include "webkit/plugins/ppapi/ppb_video_decoder_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ppapi/c/dev/pp_video_dev.h" | 8 #include "ppapi/c/dev/pp_video_dev.h" |
9 #include "ppapi/c/dev/ppb_video_decoder_dev.h" | 9 #include "ppapi/c/dev/ppb_video_decoder_dev.h" |
10 #include "ppapi/c/pp_completion_callback.h" | 10 #include "ppapi/c/pp_completion_callback.h" |
11 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
12 #include "webkit/glue/plugins/pepper_common.h" | 12 #include "webkit/plugins/ppapi/common.h" |
13 #include "webkit/glue/plugins/pepper_file_ref.h" | 13 #include "webkit/plugins/ppapi/plugin_instance.h" |
14 #include "webkit/glue/plugins/pepper_plugin_instance.h" | 14 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
15 #include "webkit/glue/plugins/pepper_resource_tracker.h" | 15 #include "webkit/plugins/ppapi/resource_tracker.h" |
16 | 16 |
17 namespace pepper { | 17 namespace webkit { |
| 18 namespace plugins { |
| 19 namespace ppapi { |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 PP_Bool GetConfig(PP_Instance instance_id, | 23 PP_Bool GetConfig(PP_Instance instance_id, |
22 PP_VideoCodecId_Dev codec, | 24 PP_VideoCodecId_Dev codec, |
23 PP_VideoConfig_Dev* configs, | 25 PP_VideoConfig_Dev* configs, |
24 int32_t config_size, | 26 int32_t config_size, |
25 int32_t *num_config) { | 27 int32_t *num_config) { |
26 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 28 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
27 *num_config = 0; | 29 *num_config = 0; |
28 if (!instance) | 30 if (!instance) |
29 return PP_FALSE; | 31 return PP_FALSE; |
30 | 32 |
31 // Get configs based on codec. | 33 // Get configs based on codec. |
32 | 34 |
33 if (configs) { | 35 if (configs) { |
34 // Fill in the array of configs. | 36 // Fill in the array of configs. |
35 } | 37 } |
36 | 38 |
37 // Update *num_config. | 39 // Update *num_config. |
38 | 40 |
39 return PP_TRUE; | 41 return PP_TRUE; |
40 } | 42 } |
41 | 43 |
42 PP_Resource Create(PP_Instance instance_id, | 44 PP_Resource Create(PP_Instance instance_id, |
43 const PP_VideoDecoderConfig_Dev* decoder_config) { | 45 const PP_VideoDecoderConfig_Dev* decoder_config) { |
44 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 46 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
45 if (!instance) | 47 if (!instance) |
46 return 0; | 48 return 0; |
47 | 49 |
48 scoped_refptr<VideoDecoder> decoder(new VideoDecoder(instance)); | 50 scoped_refptr<PPB_VideoDecoder_Impl> decoder( |
| 51 new PPB_VideoDecoder_Impl(instance)); |
49 | 52 |
50 if (!decoder->Init(*decoder_config)) | 53 if (!decoder->Init(*decoder_config)) |
51 return 0; | 54 return 0; |
52 | 55 |
53 return decoder->GetReference(); | 56 return decoder->GetReference(); |
54 } | 57 } |
55 | 58 |
56 PP_Bool Decode(PP_Resource decoder_id, | 59 PP_Bool Decode(PP_Resource decoder_id, |
57 PP_VideoCompressedDataBuffer_Dev* input_buffer) { | 60 PP_VideoCompressedDataBuffer_Dev* input_buffer) { |
58 scoped_refptr<VideoDecoder> decoder( | 61 scoped_refptr<PPB_VideoDecoder_Impl> decoder( |
59 Resource::GetAs<VideoDecoder>(decoder_id)); | 62 Resource::GetAs<PPB_VideoDecoder_Impl>(decoder_id)); |
60 if (!decoder) | 63 if (!decoder) |
61 return PP_FALSE; | 64 return PP_FALSE; |
62 | 65 |
63 decoder->Decode(*input_buffer); | 66 decoder->Decode(*input_buffer); |
64 return PP_TRUE; | 67 return PP_TRUE; |
65 } | 68 } |
66 | 69 |
67 int32_t Flush(PP_Resource decoder_id, PP_CompletionCallback callback) { | 70 int32_t Flush(PP_Resource decoder_id, PP_CompletionCallback callback) { |
68 scoped_refptr<VideoDecoder> decoder( | 71 scoped_refptr<PPB_VideoDecoder_Impl> decoder( |
69 Resource::GetAs<VideoDecoder>(decoder_id)); | 72 Resource::GetAs<PPB_VideoDecoder_Impl>(decoder_id)); |
70 if (!decoder) | 73 if (!decoder) |
71 return PP_ERROR_BADRESOURCE; | 74 return PP_ERROR_BADRESOURCE; |
72 | 75 |
73 return decoder->Flush(callback); | 76 return decoder->Flush(callback); |
74 } | 77 } |
75 | 78 |
76 PP_Bool ReturnUncompressedDataBuffer(PP_Resource decoder_id, | 79 PP_Bool ReturnUncompressedDataBuffer( |
77 PP_VideoUncompressedDataBuffer_Dev* buffer) { | 80 PP_Resource decoder_id, |
78 scoped_refptr<VideoDecoder> decoder( | 81 PP_VideoUncompressedDataBuffer_Dev* buffer) { |
79 Resource::GetAs<VideoDecoder>(decoder_id)); | 82 scoped_refptr<PPB_VideoDecoder_Impl> decoder( |
| 83 Resource::GetAs<PPB_VideoDecoder_Impl>(decoder_id)); |
80 if (!decoder) | 84 if (!decoder) |
81 return PP_FALSE; | 85 return PP_FALSE; |
82 | 86 |
83 return BoolToPPBool(decoder->ReturnUncompressedDataBuffer(*buffer)); | 87 return BoolToPPBool(decoder->ReturnUncompressedDataBuffer(*buffer)); |
84 } | 88 } |
85 | 89 |
86 const PPB_VideoDecoder_Dev ppb_videodecoder = { | 90 const PPB_VideoDecoder_Dev ppb_videodecoder = { |
87 &GetConfig, | 91 &GetConfig, |
88 &Create, | 92 &Create, |
89 &Decode, | 93 &Decode, |
90 &Flush, | 94 &Flush, |
91 &ReturnUncompressedDataBuffer | 95 &ReturnUncompressedDataBuffer |
92 }; | 96 }; |
93 | 97 |
94 } // namespace | 98 } // namespace |
95 | 99 |
96 VideoDecoder::VideoDecoder(PluginInstance* instance) | 100 PPB_VideoDecoder_Impl::PPB_VideoDecoder_Impl(PluginInstance* instance) |
97 : Resource(instance->module()), | 101 : Resource(instance->module()), |
98 instance_(instance) { | 102 instance_(instance) { |
99 } | 103 } |
100 | 104 |
101 VideoDecoder::~VideoDecoder() { | 105 PPB_VideoDecoder_Impl::~PPB_VideoDecoder_Impl() { |
102 } | 106 } |
103 | 107 |
104 // static | 108 // static |
105 const PPB_VideoDecoder_Dev* VideoDecoder::GetInterface() { | 109 const PPB_VideoDecoder_Dev* PPB_VideoDecoder_Impl::GetInterface() { |
106 return &ppb_videodecoder; | 110 return &ppb_videodecoder; |
107 } | 111 } |
108 | 112 |
109 VideoDecoder* VideoDecoder::AsVideoDecoder() { | 113 PPB_VideoDecoder_Impl* PPB_VideoDecoder_Impl::AsVideoDecoder() { |
110 return this; | 114 return this; |
111 } | 115 } |
112 | 116 |
113 bool VideoDecoder::Init(const PP_VideoDecoderConfig_Dev& decoder_config) { | 117 bool PPB_VideoDecoder_Impl::Init( |
| 118 const PP_VideoDecoderConfig_Dev& decoder_config) { |
114 if (!instance()) | 119 if (!instance()) |
115 return false; | 120 return false; |
116 | 121 |
117 platform_video_decoder_.reset( | 122 platform_video_decoder_.reset( |
118 instance()->delegate()->CreateVideoDecoder(decoder_config)); | 123 instance()->delegate()->CreateVideoDecoder(decoder_config)); |
119 | 124 |
120 return platform_video_decoder_.get()? true : false; | 125 return platform_video_decoder_.get()? true : false; |
121 } | 126 } |
122 | 127 |
123 bool VideoDecoder::Decode(PP_VideoCompressedDataBuffer_Dev& input_buffer) { | 128 bool PPB_VideoDecoder_Impl::Decode( |
| 129 PP_VideoCompressedDataBuffer_Dev& input_buffer) { |
124 if (!platform_video_decoder_.get()) | 130 if (!platform_video_decoder_.get()) |
125 return false; | 131 return false; |
126 | 132 |
127 return platform_video_decoder_->Decode(input_buffer); | 133 return platform_video_decoder_->Decode(input_buffer); |
128 } | 134 } |
129 | 135 |
130 int32_t VideoDecoder::Flush(PP_CompletionCallback& callback) { | 136 int32_t PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback& callback) { |
131 if (!platform_video_decoder_.get()) | 137 if (!platform_video_decoder_.get()) |
132 return PP_ERROR_FAILED; | 138 return PP_ERROR_FAILED; |
133 | 139 |
134 return platform_video_decoder_->Flush(callback); | 140 return platform_video_decoder_->Flush(callback); |
135 } | 141 } |
136 | 142 |
137 bool VideoDecoder::ReturnUncompressedDataBuffer( | 143 bool PPB_VideoDecoder_Impl::ReturnUncompressedDataBuffer( |
138 PP_VideoUncompressedDataBuffer_Dev& buffer) { | 144 PP_VideoUncompressedDataBuffer_Dev& buffer) { |
139 if (!platform_video_decoder_.get()) | 145 if (!platform_video_decoder_.get()) |
140 return false; | 146 return false; |
141 | 147 |
142 return platform_video_decoder_->ReturnUncompressedDataBuffer(buffer); | 148 return platform_video_decoder_->ReturnUncompressedDataBuffer(buffer); |
143 } | 149 } |
144 | 150 |
145 } // namespace pepper | 151 } // namespace ppapi |
| 152 } // namespace plugins |
| 153 } // namespace webkit |
| 154 |
OLD | NEW |