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