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

Unified Diff: ppapi/cpp/video.cc

Issue 13461010: Add PP_VideoFrame, PPB_VideoReader, and PPB_VideoWriter APIs to Pepper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698