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

Side by Side Diff: content/renderer/media/webrtc/webrtc_video_frame_adapter.cc

Issue 2456443002: Add callback to copy texture backed frames in WebRtcVideoFrameAdapter (Closed)
Patch Set: mcasas@ comments. Created 4 years, 1 month 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
« no previous file with comments | « content/renderer/media/webrtc/webrtc_video_frame_adapter.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/renderer/media/webrtc/webrtc_video_frame_adapter.h" 5 #include "content/renderer/media/webrtc/webrtc_video_frame_adapter.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace {
10
11 void IsValidFrame(const scoped_refptr<media::VideoFrame>& frame) {
12 // Paranoia checks.
13 DCHECK(frame);
14 DCHECK(media::VideoFrame::IsValidConfig(
15 frame->format(), frame->storage_type(), frame->coded_size(),
16 frame->visible_rect(), frame->natural_size()));
17 DCHECK(media::PIXEL_FORMAT_I420 == frame->format() ||
18 media::PIXEL_FORMAT_YV12 == frame->format());
19 CHECK(reinterpret_cast<void*>(frame->data(media::VideoFrame::kYPlane)));
20 CHECK(reinterpret_cast<void*>(frame->data(media::VideoFrame::kUPlane)));
21 CHECK(reinterpret_cast<void*>(frame->data(media::VideoFrame::kVPlane)));
22 CHECK(frame->stride(media::VideoFrame::kYPlane));
23 CHECK(frame->stride(media::VideoFrame::kUPlane));
24 CHECK(frame->stride(media::VideoFrame::kVPlane));
25 }
26
27 } // anonymous namespace
28
9 namespace content { 29 namespace content {
10 30
11 WebRtcVideoFrameAdapter::WebRtcVideoFrameAdapter( 31 WebRtcVideoFrameAdapter::WebRtcVideoFrameAdapter(
12 const scoped_refptr<media::VideoFrame>& frame) 32 const scoped_refptr<media::VideoFrame>& frame,
13 : frame_(frame) { 33 const CopyTextureFrameCallback& copy_texture_callback)
14 } 34 : frame_(frame), copy_texture_callback_(copy_texture_callback) {}
15 35
16 WebRtcVideoFrameAdapter::~WebRtcVideoFrameAdapter() { 36 WebRtcVideoFrameAdapter::~WebRtcVideoFrameAdapter() {
17 } 37 }
18 38
19 int WebRtcVideoFrameAdapter::width() const { 39 int WebRtcVideoFrameAdapter::width() const {
20 return frame_->visible_rect().width(); 40 return frame_->visible_rect().width();
21 } 41 }
22 42
23 int WebRtcVideoFrameAdapter::height() const { 43 int WebRtcVideoFrameAdapter::height() const {
24 return frame_->visible_rect().height(); 44 return frame_->visible_rect().height();
(...skipping 13 matching lines...) Expand all
38 return frame_->stride(media::VideoFrame::kYPlane); 58 return frame_->stride(media::VideoFrame::kYPlane);
39 } 59 }
40 int WebRtcVideoFrameAdapter::StrideU() const { 60 int WebRtcVideoFrameAdapter::StrideU() const {
41 return frame_->stride(media::VideoFrame::kUPlane); 61 return frame_->stride(media::VideoFrame::kUPlane);
42 } 62 }
43 int WebRtcVideoFrameAdapter::StrideV() const { 63 int WebRtcVideoFrameAdapter::StrideV() const {
44 return frame_->stride(media::VideoFrame::kVPlane); 64 return frame_->stride(media::VideoFrame::kVPlane);
45 } 65 }
46 66
47 void* WebRtcVideoFrameAdapter::native_handle() const { 67 void* WebRtcVideoFrameAdapter::native_handle() const {
68 // Keep native handle for shared memory backed frames, so that we can use
69 // the existing handle to share for hw encode.
48 if (frame_->HasTextures() || 70 if (frame_->HasTextures() ||
49 frame_->storage_type() == media::VideoFrame::STORAGE_SHMEM) 71 frame_->storage_type() == media::VideoFrame::STORAGE_SHMEM)
50 return frame_.get(); 72 return frame_.get();
51 return nullptr; 73 return nullptr;
52 } 74 }
53 75
54 rtc::scoped_refptr<webrtc::VideoFrameBuffer> 76 rtc::scoped_refptr<webrtc::VideoFrameBuffer>
55 WebRtcVideoFrameAdapter::NativeToI420Buffer() { 77 WebRtcVideoFrameAdapter::NativeToI420Buffer() {
56 CHECK(media::VideoFrame::IsValidConfig( 78 if (frame_->storage_type() == media::VideoFrame::STORAGE_SHMEM) {
57 frame_->format(), frame_->storage_type(), frame_->coded_size(), 79 IsValidFrame(frame_);
58 frame_->visible_rect(), frame_->natural_size())); 80 return this;
59 CHECK_EQ(media::PIXEL_FORMAT_I420, frame_->format()); 81 }
60 CHECK(reinterpret_cast<void*>(frame_->data(media::VideoFrame::kYPlane))); 82
61 CHECK(reinterpret_cast<void*>(frame_->data(media::VideoFrame::kUPlane))); 83 if (frame_->HasTextures()) {
62 CHECK(reinterpret_cast<void*>(frame_->data(media::VideoFrame::kVPlane))); 84 if (copy_texture_callback_.is_null()) {
63 CHECK(frame_->stride(media::VideoFrame::kYPlane)); 85 DLOG(ERROR) << "Texture backed frame cannot be copied.";
64 CHECK(frame_->stride(media::VideoFrame::kUPlane)); 86 return nullptr;
65 CHECK(frame_->stride(media::VideoFrame::kVPlane)); 87 }
66 return this; 88
89 scoped_refptr<media::VideoFrame> new_frame;
90 copy_texture_callback_.Run(frame_, &new_frame);
91 if (!new_frame)
92 return nullptr;
93 frame_ = new_frame;
94 IsValidFrame(frame_);
95 return this;
96 }
97
98 NOTREACHED();
99 return nullptr;
67 } 100 }
68 101
69 } // namespace content 102 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc/webrtc_video_frame_adapter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698