summaryrefslogtreecommitdiffstats
path: root/webkit/media/webvideoframe_impl.cc
blob: 58cfa627a70a7e3c7ee11f4e01ce8391091bedbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "webkit/media/webvideoframe_impl.h"

#include "base/logging.h"
#include "media/base/video_frame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebVideoFrame.h"

using WebKit::WebVideoFrame;

namespace webkit_media {

media::VideoFrame* WebVideoFrameImpl::toVideoFrame(
    WebVideoFrame* web_video_frame) {
  WebVideoFrameImpl* wrapped_frame =
      static_cast<WebVideoFrameImpl*>(web_video_frame);
  if (wrapped_frame)
    return wrapped_frame->video_frame_.get();
  return NULL;
}

WebVideoFrameImpl::WebVideoFrameImpl(
    scoped_refptr<media::VideoFrame> video_frame)
    : video_frame_(video_frame) {
}

WebVideoFrameImpl::~WebVideoFrameImpl() {}

#define COMPILE_ASSERT_MATCHING_ENUM(webkit_name, chromium_name) \
    COMPILE_ASSERT(int(WebKit::WebVideoFrame::webkit_name) == \
                   int(media::VideoFrame::chromium_name), \
                   mismatching_enums)
COMPILE_ASSERT_MATCHING_ENUM(FormatInvalid, INVALID);
COMPILE_ASSERT_MATCHING_ENUM(FormatRGB555, RGB555);
COMPILE_ASSERT_MATCHING_ENUM(FormatRGB565, RGB565);
COMPILE_ASSERT_MATCHING_ENUM(FormatRGB24, RGB24);
COMPILE_ASSERT_MATCHING_ENUM(FormatRGB32, RGB32);
COMPILE_ASSERT_MATCHING_ENUM(FormatRGBA, RGBA);
COMPILE_ASSERT_MATCHING_ENUM(FormatYV12, YV12);
COMPILE_ASSERT_MATCHING_ENUM(FormatYV16, YV16);
COMPILE_ASSERT_MATCHING_ENUM(FormatNV12, NV12);
COMPILE_ASSERT_MATCHING_ENUM(FormatEmpty, EMPTY);
COMPILE_ASSERT_MATCHING_ENUM(FormatASCII, ASCII);
COMPILE_ASSERT_MATCHING_ENUM(FormatI420, I420);
COMPILE_ASSERT_MATCHING_ENUM(FormatNativeTexture, NATIVE_TEXTURE);

WebVideoFrame::Format WebVideoFrameImpl::format() const {
  if (video_frame_.get())
    return static_cast<WebVideoFrame::Format>(video_frame_->format());
  return WebVideoFrame::FormatInvalid;
}

unsigned WebVideoFrameImpl::width() const {
  if (video_frame_.get())
    return video_frame_->width();
  return 0;
}

unsigned WebVideoFrameImpl::height() const {
  if (video_frame_.get())
    return video_frame_->height();
  return 0;
}

unsigned WebVideoFrameImpl::planes() const {
  if (!video_frame_.get())
    return 0;
  switch (video_frame_->format()) {
    case media::VideoFrame::RGB555:
    case media::VideoFrame::RGB565:
    case media::VideoFrame::RGB24:
    case media::VideoFrame::RGB32:
    case media::VideoFrame::RGBA:
      return 1;
    case media::VideoFrame::YV12:
    case media::VideoFrame::YV16:
      return 3;
    case media::VideoFrame::INVALID:
    case media::VideoFrame::NV12:
    case media::VideoFrame::EMPTY:
    case media::VideoFrame::ASCII:
    case media::VideoFrame::I420:
      break;
    case media::VideoFrame::NATIVE_TEXTURE:
      return 0;
  }
  NOTREACHED();
  return 0;
}

int WebVideoFrameImpl::stride(unsigned plane) const {
  if (video_frame_.get())
    return static_cast<int>(video_frame_->stride(plane));
  return 0;
}

const void* WebVideoFrameImpl::data(unsigned plane) const {
  if (!video_frame_.get() || format() == FormatNativeTexture)
    return NULL;
  return static_cast<const void*>(video_frame_->data(plane));
}

unsigned WebVideoFrameImpl::textureId() const {
  if (!video_frame_.get() || format() != FormatNativeTexture)
    return 0;
  return video_frame_->texture_id();
}

unsigned WebVideoFrameImpl::textureTarget() const {
  if (!video_frame_.get() || format() != FormatNativeTexture)
    return 0;
  return video_frame_->texture_target();
}

}  // namespace webkit_media