Chromium Code Reviews| Index: ppapi/cpp/video.cc |
| diff --git a/ppapi/cpp/video.cc b/ppapi/cpp/video.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4b90b873324670ff5893c2750a7205da2527cde2 |
| --- /dev/null |
| +++ b/ppapi/cpp/video.cc |
| @@ -0,0 +1,116 @@ |
| +// Copyright (c) 2013 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 "ppapi/cpp/video.h" |
| + |
| +#include "ppapi/c/pp_errors.h" |
| +#include "ppapi/c/ppb_var.h" |
| +#include "ppapi/c/ppb_video_reader.h" |
| +#include "ppapi/c/ppb_video_writer.h" |
| +#include "ppapi/cpp/completion_callback.h" |
| +#include "ppapi/cpp/image_data.h" |
| +#include "ppapi/cpp/instance_handle.h" |
| +#include "ppapi/cpp/module.h" |
| +#include "ppapi/cpp/module_impl.h" |
| +#include "ppapi/cpp/var.h" |
| + |
| +namespace pp { |
| + |
| +namespace { |
| + |
| +template <> const char* interface_name<PPB_VideoReader_1_0>() { |
| + return PPB_VIDEOREADER_INTERFACE_1_0; |
| +} |
| +template <> const char* interface_name<PPB_VideoWriter_1_0>() { |
| + return PPB_VIDEOWRITER_INTERFACE_1_0; |
| +} |
| + |
| +} // namespace |
| + |
| +// VideoFrame ------------------------------------------------------------------ |
| + |
| +VideoFrame::VideoFrame() { |
| + video_frame_.image_data = image_data_.pp_resource(); |
| + set_timestamp(0); |
| +} |
| + |
| +VideoFrame::VideoFrame( |
| + PassRef, |
| + const PP_VideoFrame& pp_video_frame) { |
| + video_frame_ = pp_video_frame; |
| + image_data_ = ImageData(PASS_REF, pp_video_frame.image_data); |
| +} |
| + |
| +VideoFrame::VideoFrame(const VideoFrame& other) { |
| + set_image_data(other.image_data()); |
| + set_timestamp(other.timestamp()); |
| +} |
| + |
| +VideoFrame::~VideoFrame() { |
| +} |
| + |
| +VideoFrame& VideoFrame::operator=(const VideoFrame& other) { |
| + if (this == &other) |
| + return *this; |
| + |
| + video_frame_ = other.video_frame_; |
| + // Be careful about the refcount of the resource, the assignment above doesn't |
| + // copy a ref. The assignments below take a ref to the new image data and copy |
| + // the PP_Resource into the wrapped video frame. |
| + image_data_ = other.image_data(); |
| + video_frame_.image_data = image_data_.pp_resource(); |
|
yzshen1
2013/04/02 19:28:39
It seems line 62 is not needed because line 57 has
bbudge
2013/04/03 10:42:29
Done.
|
| + |
| + return *this; |
| +} |
| + |
| +// VideoReader ----------------------------------------------------------------- |
| + |
| +VideoReader::VideoReader() { |
| +} |
| + |
| +VideoReader::VideoReader(const InstanceHandle& instance) { |
| + if (!has_interface<PPB_VideoReader_1_0>()) |
| + return; |
| + PassRefFromConstructor(get_interface<PPB_VideoReader_1_0>()->Create( |
| + instance.pp_instance())); |
| +} |
| + |
| +VideoReader::VideoReader(const VideoReader& other) |
| + : Resource(other) { |
| +} |
| + |
| +VideoReader::VideoReader(PassRef, PP_Resource resource) |
| + : Resource(PASS_REF, resource) { |
| +} |
| + |
| +int32_t VideoReader::Open(const Var& stream_id, |
| + const CompletionCallback& cc) { |
| + if (has_interface<PPB_VideoReader_1_0>()) { |
| + int32_t result = |
| + get_interface<PPB_VideoReader_1_0>()->Open( |
| + pp_resource(), |
| + stream_id.pp_var(), cc.pp_completion_callback()); |
| + return result; |
| + } |
| + return cc.MayForce(PP_ERROR_NOINTERFACE); |
| +} |
| + |
| +int32_t VideoReader::Close() { |
| + if (has_interface<PPB_VideoReader_1_0>()) { |
| + return get_interface<PPB_VideoReader_1_0>()->Close(pp_resource()); |
| + } |
| + return PP_ERROR_NOINTERFACE; |
| +} |
| + |
| +int32_t VideoReader::GetNextFrame( |
| + const CompletionCallbackWithOutput<VideoFrame>& cc) { |
| + if (has_interface<PPB_VideoReader_1_0>()) { |
| + return get_interface<PPB_VideoReader_1_0>()->GetNextFrame( |
| + pp_resource(), |
| + cc.output(), cc.pp_completion_callback()); |
| + } |
| + return cc.MayForce(PP_ERROR_NOINTERFACE); |
| +} |
| + |
|
yzshen1
2013/04/02 19:28:39
The writer implementation is missing.
bbudge
2013/04/03 10:42:29
Done.
|
| +} // namespace pp |