OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_RENDERER_MEDIA_GLES2_VIDEO_DECODE_CONTEXT_H_ | |
6 #define CHROME_RENDERER_MEDIA_GLES2_VIDEO_DECODE_CONTEXT_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "media/video/video_decode_context.h" | |
11 | |
12 class MessageLoop; | |
13 | |
14 namespace ggl { | |
15 class Context; | |
16 } // namespace ggl | |
17 | |
18 // FUNCTIONS | |
19 // | |
20 // This is a class that provides a video decode context using a ggl::Context | |
21 // backend. | |
22 // | |
23 // It provides resources for a VideoDecodeEngine to store decoded video frames. | |
24 // | |
25 // This class is aware of the command buffer implementation of GLES2 inside the | |
26 // Chrome renderer and keeps a reference of ggl::Context. It might use GLES2 | |
27 // commands specific to Chrome's renderer process to provide needed resources. | |
28 // | |
29 // There are two different kinds of video frame storage provided by this class: | |
30 // 1. Memory mapped textures (aka software decoding mode). | |
31 // Each texture is memory mapped and appears to the VideoDecodeEngine as | |
32 // system memory. | |
33 // | |
34 // The usage of the textures is that the VideoDecodeEngine is performing | |
35 // software video decoding and use them as if they are allocated in plain | |
36 // system memory (in fact they are allocated in system memory and shared | |
37 // bwith the GPU process). An additional step of uploading the content to | |
38 // video memory is needed. Since VideoDecodeEngine is unaware of the video | |
39 // memory, this upload operation is performed by calling | |
40 // ConvertToVideoFrame(). | |
41 // | |
42 // After the content is uploaded to video memory, WebKit will see the video | |
43 // frame as textures and will perform the necessary operations for | |
44 // rendering. | |
45 // | |
46 // 2. Opaque textures (aka hardware decoding mode). | |
47 // In this mode of operation each video frame is backed by some opaque | |
48 // textures. This is used only when hardware video decoding is used. The | |
49 // textures needs to be generated and allocated inside the renderer process | |
50 // first. This will establish a translation between texture ID in the | |
51 // renderer process and the GPU process. | |
52 // | |
53 // The texture ID generated is used by IpcVideoDecodeEngine only to be sent | |
54 // the GPU process. Inside the GPU process the texture ID is translated to | |
55 // a real texture ID inside the actual context. The real texture ID is then | |
56 // assigned to the hardware video decoder for storing the video frame. | |
57 // | |
58 // WebKit will see the video frame as a normal textures and perform | |
59 // necessary render operations. | |
60 // | |
61 // In both operation modes, the objective is to have WebKit see the video frames | |
62 // as regular textures. | |
63 // | |
64 // THREAD SEMANTICS | |
65 // | |
66 // All methods of this class can be called on any thread. GLES2 context and all | |
67 // OpenGL method calls are accessed on the Render Thread. As as result all Tasks | |
68 // given to this object are executed on the Render Thread. | |
69 // | |
70 // Since this class is not refcounted, it is important to destroy objects of | |
71 // this class only when the Task given to Destroy() is called. | |
72 // | |
73 class Gles2VideoDecodeContext : public media::VideoDecodeContext { | |
74 public: | |
75 // |message_loop| is the message of the Render Thread. | |
76 // |memory_mapped| determines if textures allocated are memory mapped. | |
77 // |context| is the graphics context for generating textures. | |
78 Gles2VideoDecodeContext(MessageLoop* message_loop, | |
79 bool memory_mapped, ggl::Context* context); | |
80 virtual ~Gles2VideoDecodeContext(); | |
81 | |
82 // media::VideoDecodeContext implementation. | |
83 virtual void* GetDevice(); | |
84 virtual void AllocateVideoFrames( | |
85 int frames_num, size_t width, size_t height, | |
86 media::VideoFrame::Format format, | |
87 std::vector<scoped_refptr<media::VideoFrame> >* frames_out, Task* task); | |
88 virtual void ReleaseAllVideoFrames(); | |
89 virtual void ConvertToVideoFrame(void* buffer, | |
90 scoped_refptr<media::VideoFrame> frame, | |
91 Task* task); | |
92 virtual void Destroy(Task* task); | |
93 | |
94 // Accessor of the current mode of this decode context. | |
95 bool IsMemoryMapped() const { return memory_mapped_; } | |
96 | |
97 private: | |
98 // Message loop for Render Thread. | |
99 MessageLoop* message_loop_; | |
100 | |
101 // Type of storage provided by this class. | |
102 bool memory_mapped_; | |
103 | |
104 // Pointer to the GLES2 context. | |
105 ggl::Context* context_; | |
106 | |
107 // VideoFrames allocated. | |
108 std::vector<scoped_refptr<media::VideoFrame> > frames_; | |
109 | |
110 DISALLOW_COPY_AND_ASSIGN(Gles2VideoDecodeContext); | |
111 }; | |
112 | |
113 #endif // CHROME_RENDERER_MEDIA_GLES2_VIDEO_DECODE_CONTEXT_H_ | |
OLD | NEW |