Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: content/renderer/pepper/pepper_media_stream_video_track_host.cc

Issue 128683003: [PPAPI] Implement media stream video track API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@video_track_impl_cl
Patch Set: Rebase it Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2014 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 #include "content/renderer/pepper/pepper_media_stream_video_track_host.h"
6
7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/c/ppb_video_frame.h"
9 #include "ppapi/shared_impl/media_stream_frame.h"
10
11 using media::VideoFrame;
12
13 namespace {
14
15 // TODO(penghuang): make it configurable.
16 const int32_t kNumberOfFrames = 4;
17
18 PP_VideoFrame_Format ToPpapiFormat(VideoFrame::Format format) {
19 switch (format) {
20 case VideoFrame::YV12:
21 return PP_VIDEOFRAME_FORMAT_YV12;
22 case VideoFrame::YV16:
23 return PP_VIDEOFRAME_FORMAT_YV16;
24 case VideoFrame::I420:
25 return PP_VIDEOFRAME_FORMAT_I420;
26 case VideoFrame::YV12A:
27 return PP_VIDEOFRAME_FORMAT_YV12A;
28 case VideoFrame::YV12J:
29 return PP_VIDEOFRAME_FORMAT_YV12J;
30 default:
31 DVLOG(1) << "Unsupported pixel format " << format;
32 return PP_VIDEOFRAME_FORMAT_UNKNOWN;
33 }
34 }
35
36 } // namespace
37
38 namespace content {
39
40 PepperMediaStreamVideoTrackHost::PepperMediaStreamVideoTrackHost(
41 RendererPpapiHost* host,
42 PP_Instance instance,
43 PP_Resource resource,
44 const blink::WebMediaStreamTrack& track)
45 : PepperMediaStreamTrackHostBase(host, instance, resource),
46 track_(track),
47 connected_(false),
48 frame_format_(VideoFrame::UNKNOWN),
49 frame_data_size_(0) {
50 DCHECK(!track_.isNull());
51 }
52
53 PepperMediaStreamVideoTrackHost::~PepperMediaStreamVideoTrackHost() {
54 OnClose();
55 }
56
57 void PepperMediaStreamVideoTrackHost::OnClose() {
58 if (connected_) {
59 MediaStreamVideoSink::RemoveFromVideoTrack(this, track_);
60 connected_ = false;
61 }
62 }
63
64 void PepperMediaStreamVideoTrackHost::OnVideoFrame(
65 const scoped_refptr<VideoFrame>& frame) {
66 DCHECK(frame);
67 PP_VideoFrame_Format ppformat = ToPpapiFormat(frame->format());
68 if (ppformat == PP_VIDEOFRAME_FORMAT_UNKNOWN)
69 return;
70
71 if (frame_size_ != frame->coded_size() || frame_format_ != frame->format()) {
72 frame_size_ = frame->coded_size();
73 frame_format_ = frame->format();
74 // TODO(penghuang): Support changing |frame_size_| & |frame_format_| more
75 // than once.
76 DCHECK(!frame_data_size_);
77 frame_data_size_ = VideoFrame::AllocationSize(frame_format_, frame_size_);
78 int32_t size = sizeof(ppapi::MediaStreamFrame::Video) + frame_data_size_;
79 InitFrames(kNumberOfFrames, size);
80 }
81
82 int32_t index = frame_buffer()->DequeueFrame();
83 // Drop frames if the underlying buffer is empty.
84 if (index < 0)
85 return;
86
87 ppapi::MediaStreamFrame::Video* ppframe =
88 &(frame_buffer()->GetFramePointer(index)->video);
89 ppframe->header.size = frame_buffer()->frame_size();
90 ppframe->header.type = ppapi::MediaStreamFrame::TYPE_VIDEO;
91 ppframe->timestamp = frame->GetTimestamp().InSecondsF();
92 ppframe->format = ppformat;
93 ppframe->size.width = frame->coded_size().width();
94 ppframe->size.height = frame->coded_size().height();
95 ppframe->data_size = frame_data_size_;
96
97 COMPILE_ASSERT(VideoFrame::kYPlane == 0, y_plane_should_be_0);
98 COMPILE_ASSERT(VideoFrame::kUPlane == 1, u_plane_should_be_1);
99 COMPILE_ASSERT(VideoFrame::kVPlane == 2, v_plane_should_be_2);
100
101 uint8_t* dst = ppframe->data;
102 for (size_t i = 0; i < VideoFrame::NumPlanes(frame->format()); ++i) {
dmichael (off chromium) 2014/01/09 21:06:47 It's a shame we have to do this copy stuff. It wou
Peng 2014/01/10 19:14:30 As my understanding, blink::MediaStreamTrack suppo
103 const uint8_t* src = frame->data(i);
104 const size_t row_bytes = frame->row_bytes(i);
105 const size_t src_stride = frame->stride(i);
106 for (int j = 0; j < frame->rows(i); ++j) {
107 memcpy(dst, src, row_bytes);
108 dst += row_bytes;
109 src += src_stride;
110 }
111 }
112 PluginEnqueueFrame(index);
113 }
114
115 void PepperMediaStreamVideoTrackHost::DidConnectPendingHostToResource() {
116 if (!connected_) {
117 MediaStreamVideoSink::AddToVideoTrack(this, track_);
118 connected_ = true;
119 }
120 }
121
122 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698