1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32 #include "VideoFrameChromiumImpl.h"
33
34 #include "VideoFrameChromium.h"
35 #include "WebVideoFrame.h"
36
37 using namespace WebCore;
38
39 namespace WebKit {
40
toWebVideoFrame(VideoFrameChromium * videoFrame)41 WebVideoFrame* VideoFrameChromiumImpl::toWebVideoFrame(VideoFrameChromium* videoFrame)
42 {
43 VideoFrameChromiumImpl* wrappedFrame = static_cast<VideoFrameChromiumImpl*>(videoFrame);
44 if (wrappedFrame)
45 return wrappedFrame->m_webVideoFrame;
46 return 0;
47 }
48
VideoFrameChromiumImpl(WebVideoFrame * webVideoFrame)49 VideoFrameChromiumImpl::VideoFrameChromiumImpl(WebVideoFrame* webVideoFrame)
50 : m_webVideoFrame(webVideoFrame)
51 {
52 }
53
surfaceType() const54 VideoFrameChromium::SurfaceType VideoFrameChromiumImpl::surfaceType() const
55 {
56 if (m_webVideoFrame)
57 return static_cast<VideoFrameChromium::SurfaceType>(m_webVideoFrame->surfaceType());
58 return TypeSystemMemory;
59 }
60
format() const61 VideoFrameChromium::Format VideoFrameChromiumImpl::format() const
62 {
63 if (m_webVideoFrame)
64 return static_cast<VideoFrameChromium::Format>(m_webVideoFrame->format());
65 return Invalid;
66 }
67
width() const68 unsigned VideoFrameChromiumImpl::width() const
69 {
70 if (m_webVideoFrame)
71 return m_webVideoFrame->width();
72 return 0;
73 }
74
width(unsigned plane) const75 unsigned VideoFrameChromiumImpl::width(unsigned plane) const
76 {
77 unsigned planeWidth = width();
78 if (format() == YV12 && plane != static_cast<unsigned>(yPlane))
79 planeWidth /= 2;
80 return planeWidth;
81 }
82
height() const83 unsigned VideoFrameChromiumImpl::height() const
84 {
85 if (m_webVideoFrame)
86 return m_webVideoFrame->height();
87 return 0;
88 }
89
height(unsigned plane) const90 unsigned VideoFrameChromiumImpl::height(unsigned plane) const
91 {
92 unsigned planeHeight = height();
93 if (format() == YV12 && plane != static_cast<unsigned>(yPlane))
94 planeHeight /= 2;
95 return planeHeight;
96 }
97
planes() const98 unsigned VideoFrameChromiumImpl::planes() const
99 {
100 if (m_webVideoFrame)
101 return m_webVideoFrame->planes();
102 return 0;
103 }
104
stride(unsigned plane) const105 int VideoFrameChromiumImpl::stride(unsigned plane) const
106 {
107 if (m_webVideoFrame)
108 return m_webVideoFrame->stride(plane);
109 return 0;
110 }
111
data(unsigned plane) const112 const void* VideoFrameChromiumImpl::data(unsigned plane) const
113 {
114 if (m_webVideoFrame)
115 return m_webVideoFrame->data(plane);
116 return 0;
117 }
118
texture(unsigned plane) const119 unsigned VideoFrameChromiumImpl::texture(unsigned plane) const
120 {
121 if (m_webVideoFrame)
122 return m_webVideoFrame->texture(plane);
123 return 0;
124 }
125
requiredTextureSize(unsigned plane) const126 const IntSize VideoFrameChromiumImpl::requiredTextureSize(unsigned plane) const
127 {
128 return IntSize(stride(plane), height(plane));
129 }
130
hasPaddingBytes(unsigned plane) const131 bool VideoFrameChromiumImpl::hasPaddingBytes(unsigned plane) const
132 {
133 if (m_webVideoFrame)
134 return stride(plane) - width(plane) > 0;
135 return false;
136 }
137
138 } // namespace WebKit
139