Move WebRtcVideoRenderFrame from webrtcvideoengine2.cc to webrtcvideoframe.h

The purpose of this CL is to be able to reuse the class WebRtcVideoRenderFrame in webrtcvideoengine.cc.

R=pbos@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/32799004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7888 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
magjed@webrtc.org
2014-12-14 11:09:23 +00:00
parent e9db7fe80c
commit e575e9c40f
3 changed files with 198 additions and 128 deletions

View File

@ -574,134 +574,6 @@ std::vector<VideoCodec> WebRtcVideoEngine2::GetSupportedCodecs() const {
return supported_codecs; return supported_codecs;
} }
// Thin map between VideoFrame and an existing webrtc::I420VideoFrame
// to avoid having to copy the rendered VideoFrame prematurely.
// This implementation is only safe to use in a const context and should never
// be written to.
class WebRtcVideoRenderFrame : public VideoFrame {
public:
explicit WebRtcVideoRenderFrame(const webrtc::I420VideoFrame* frame)
: frame_(frame) {}
virtual bool InitToBlack(int w,
int h,
size_t pixel_width,
size_t pixel_height,
int64_t elapsed_time,
int64_t time_stamp) OVERRIDE {
UNIMPLEMENTED;
return false;
}
virtual bool Reset(uint32 fourcc,
int w,
int h,
int dw,
int dh,
uint8* sample,
size_t sample_size,
size_t pixel_width,
size_t pixel_height,
int64_t elapsed_time,
int64_t time_stamp,
int rotation) OVERRIDE {
UNIMPLEMENTED;
return false;
}
virtual size_t GetWidth() const OVERRIDE {
return static_cast<size_t>(frame_->width());
}
virtual size_t GetHeight() const OVERRIDE {
return static_cast<size_t>(frame_->height());
}
virtual const uint8* GetYPlane() const OVERRIDE {
return frame_->buffer(webrtc::kYPlane);
}
virtual const uint8* GetUPlane() const OVERRIDE {
return frame_->buffer(webrtc::kUPlane);
}
virtual const uint8* GetVPlane() const OVERRIDE {
return frame_->buffer(webrtc::kVPlane);
}
virtual uint8* GetYPlane() OVERRIDE {
UNIMPLEMENTED;
return NULL;
}
virtual uint8* GetUPlane() OVERRIDE {
UNIMPLEMENTED;
return NULL;
}
virtual uint8* GetVPlane() OVERRIDE {
UNIMPLEMENTED;
return NULL;
}
virtual int32 GetYPitch() const OVERRIDE {
return frame_->stride(webrtc::kYPlane);
}
virtual int32 GetUPitch() const OVERRIDE {
return frame_->stride(webrtc::kUPlane);
}
virtual int32 GetVPitch() const OVERRIDE {
return frame_->stride(webrtc::kVPlane);
}
virtual void* GetNativeHandle() const OVERRIDE { return NULL; }
virtual size_t GetPixelWidth() const OVERRIDE { return 1; }
virtual size_t GetPixelHeight() const OVERRIDE { return 1; }
virtual int64_t GetElapsedTime() const OVERRIDE {
// Convert millisecond render time to ns timestamp.
return frame_->render_time_ms() * rtc::kNumNanosecsPerMillisec;
}
virtual int64_t GetTimeStamp() const OVERRIDE {
// Convert 90K rtp timestamp to ns timestamp.
return (frame_->timestamp() / 90) * rtc::kNumNanosecsPerMillisec;
}
virtual void SetElapsedTime(int64_t elapsed_time) OVERRIDE { UNIMPLEMENTED; }
virtual void SetTimeStamp(int64_t time_stamp) OVERRIDE { UNIMPLEMENTED; }
virtual int GetRotation() const OVERRIDE {
UNIMPLEMENTED;
return ROTATION_0;
}
virtual VideoFrame* Copy() const OVERRIDE {
UNIMPLEMENTED;
return NULL;
}
virtual bool MakeExclusive() OVERRIDE {
UNIMPLEMENTED;
return false;
}
virtual size_t CopyToBuffer(uint8* buffer, size_t size) const {
UNIMPLEMENTED;
return 0;
}
protected:
virtual VideoFrame* CreateEmptyFrame(int w,
int h,
size_t pixel_width,
size_t pixel_height,
int64_t elapsed_time,
int64_t time_stamp) const OVERRIDE {
WebRtcVideoFrame* frame = new WebRtcVideoFrame();
frame->InitToBlack(
w, h, pixel_width, pixel_height, elapsed_time, time_stamp);
return frame;
}
private:
const webrtc::I420VideoFrame* const frame_;
};
WebRtcVideoChannel2::WebRtcVideoChannel2( WebRtcVideoChannel2::WebRtcVideoChannel2(
WebRtcCallFactory* call_factory, WebRtcCallFactory* call_factory,
WebRtcVoiceEngine* voice_engine, WebRtcVoiceEngine* voice_engine,

View File

@ -33,6 +33,11 @@
#include "talk/media/base/videocapturer.h" #include "talk/media/base/videocapturer.h"
#include "talk/media/base/videocommon.h" #include "talk/media/base/videocommon.h"
#include "webrtc/base/logging.h" #include "webrtc/base/logging.h"
#include "webrtc/video_frame.h"
#define UNIMPLEMENTED \
LOG(LS_ERROR) << "Call to unimplemented function " << __FUNCTION__; \
ASSERT(false)
namespace cricket { namespace cricket {
@ -354,4 +359,132 @@ void WebRtcVideoFrame::InitToEmptyBuffer(int w, int h, size_t pixel_width,
elapsed_time, time_stamp, 0); elapsed_time, time_stamp, 0);
} }
WebRtcVideoRenderFrame::WebRtcVideoRenderFrame(
const webrtc::I420VideoFrame* frame)
: frame_(frame) {
}
bool WebRtcVideoRenderFrame::InitToBlack(int w,
int h,
size_t pixel_width,
size_t pixel_height,
int64_t elapsed_time,
int64_t time_stamp) {
UNIMPLEMENTED;
return false;
}
bool WebRtcVideoRenderFrame::Reset(uint32 fourcc,
int w,
int h,
int dw,
int dh,
uint8* sample,
size_t sample_size,
size_t pixel_width,
size_t pixel_height,
int64_t elapsed_time,
int64_t time_stamp,
int rotation) {
UNIMPLEMENTED;
return false;
}
size_t WebRtcVideoRenderFrame::GetWidth() const {
return static_cast<size_t>(frame_->width());
}
size_t WebRtcVideoRenderFrame::GetHeight() const {
return static_cast<size_t>(frame_->height());
}
const uint8* WebRtcVideoRenderFrame::GetYPlane() const {
return frame_->buffer(webrtc::kYPlane);
}
const uint8* WebRtcVideoRenderFrame::GetUPlane() const {
return frame_->buffer(webrtc::kUPlane);
}
const uint8* WebRtcVideoRenderFrame::GetVPlane() const {
return frame_->buffer(webrtc::kVPlane);
}
uint8* WebRtcVideoRenderFrame::GetYPlane() {
UNIMPLEMENTED;
return NULL;
}
uint8* WebRtcVideoRenderFrame::GetUPlane() {
UNIMPLEMENTED;
return NULL;
}
uint8* WebRtcVideoRenderFrame::GetVPlane() {
UNIMPLEMENTED;
return NULL;
}
int32 WebRtcVideoRenderFrame::GetYPitch() const {
return frame_->stride(webrtc::kYPlane);
}
int32 WebRtcVideoRenderFrame::GetUPitch() const {
return frame_->stride(webrtc::kUPlane);
}
int32 WebRtcVideoRenderFrame::GetVPitch() const {
return frame_->stride(webrtc::kVPlane);
}
void* WebRtcVideoRenderFrame::GetNativeHandle() const {
return NULL;
}
size_t WebRtcVideoRenderFrame::GetPixelWidth() const {
return 1;
}
size_t WebRtcVideoRenderFrame::GetPixelHeight() const {
return 1;
}
int64_t WebRtcVideoRenderFrame::GetElapsedTime() const {
// Convert millisecond render time to ns timestamp.
return frame_->render_time_ms() * rtc::kNumNanosecsPerMillisec;
}
int64_t WebRtcVideoRenderFrame::GetTimeStamp() const {
// Convert 90K rtp timestamp to ns timestamp.
return (frame_->timestamp() / 90) * rtc::kNumNanosecsPerMillisec;
}
void WebRtcVideoRenderFrame::SetElapsedTime(int64_t elapsed_time) {
UNIMPLEMENTED;
}
void WebRtcVideoRenderFrame::SetTimeStamp(int64_t time_stamp) {
UNIMPLEMENTED;
}
int WebRtcVideoRenderFrame::GetRotation() const {
UNIMPLEMENTED;
return ROTATION_0;
}
VideoFrame* WebRtcVideoRenderFrame::Copy() const {
UNIMPLEMENTED;
return NULL;
}
bool WebRtcVideoRenderFrame::MakeExclusive() {
UNIMPLEMENTED;
return false;
}
size_t WebRtcVideoRenderFrame::CopyToBuffer(uint8* buffer, size_t size) const {
UNIMPLEMENTED;
return 0;
}
VideoFrame* WebRtcVideoRenderFrame::CreateEmptyFrame(int w,
int h,
size_t pixel_width,
size_t pixel_height,
int64_t elapsed_time,
int64_t time_stamp) const {
WebRtcVideoFrame* frame = new WebRtcVideoFrame();
frame->InitToBlack(w, h, pixel_width, pixel_height, elapsed_time, time_stamp);
return frame;
}
} // namespace cricket } // namespace cricket

View File

@ -35,6 +35,10 @@
#include "webrtc/common_types.h" #include "webrtc/common_types.h"
#include "webrtc/modules/interface/module_common_types.h" #include "webrtc/modules/interface/module_common_types.h"
namespace webrtc {
class I420VideoFrame;
};
namespace cricket { namespace cricket {
struct CapturedFrame; struct CapturedFrame;
@ -129,6 +133,67 @@ class WebRtcVideoFrame : public VideoFrame {
int rotation_; int rotation_;
}; };
// Thin map between VideoFrame and an existing webrtc::I420VideoFrame
// to avoid having to copy the rendered VideoFrame prematurely.
// This implementation is only safe to use in a const context and should never
// be written to.
class WebRtcVideoRenderFrame : public VideoFrame {
public:
explicit WebRtcVideoRenderFrame(const webrtc::I420VideoFrame* frame);
virtual bool InitToBlack(int w,
int h,
size_t pixel_width,
size_t pixel_height,
int64_t elapsed_time,
int64_t time_stamp) OVERRIDE;
virtual bool Reset(uint32 fourcc,
int w,
int h,
int dw,
int dh,
uint8* sample,
size_t sample_size,
size_t pixel_width,
size_t pixel_height,
int64_t elapsed_time,
int64_t time_stamp,
int rotation) OVERRIDE;
virtual size_t GetWidth() const OVERRIDE;
virtual size_t GetHeight() const OVERRIDE;
virtual const uint8* GetYPlane() const OVERRIDE;
virtual const uint8* GetUPlane() const OVERRIDE;
virtual const uint8* GetVPlane() const OVERRIDE;
virtual uint8* GetYPlane() OVERRIDE;
virtual uint8* GetUPlane() OVERRIDE;
virtual uint8* GetVPlane() OVERRIDE;
virtual int32 GetYPitch() const OVERRIDE;
virtual int32 GetUPitch() const OVERRIDE;
virtual int32 GetVPitch() const OVERRIDE;
virtual void* GetNativeHandle() const OVERRIDE;
virtual size_t GetPixelWidth() const OVERRIDE;
virtual size_t GetPixelHeight() const OVERRIDE;
virtual int64_t GetElapsedTime() const OVERRIDE;
virtual int64_t GetTimeStamp() const OVERRIDE;
virtual void SetElapsedTime(int64_t elapsed_time) OVERRIDE;
virtual void SetTimeStamp(int64_t time_stamp) OVERRIDE;
virtual int GetRotation() const OVERRIDE;
virtual VideoFrame* Copy() const OVERRIDE;
virtual bool MakeExclusive() OVERRIDE;
virtual size_t CopyToBuffer(uint8* buffer, size_t size) const OVERRIDE;
protected:
virtual VideoFrame* CreateEmptyFrame(int w,
int h,
size_t pixel_width,
size_t pixel_height,
int64_t elapsed_time,
int64_t time_stamp) const OVERRIDE;
private:
const webrtc::I420VideoFrame* const frame_;
};
} // namespace cricket } // namespace cricket
#endif // TALK_MEDIA_WEBRTCVIDEOFRAME_H_ #endif // TALK_MEDIA_WEBRTCVIDEOFRAME_H_