OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 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 "ppapi/cpp/video.h" |
| 6 |
| 7 #include "ppapi/c/pp_errors.h" |
| 8 #include "ppapi/c/ppb_var.h" |
| 9 #include "ppapi/c/ppb_video_reader.h" |
| 10 #include "ppapi/c/ppb_video_writer.h" |
| 11 #include "ppapi/cpp/completion_callback.h" |
| 12 #include "ppapi/cpp/image_data.h" |
| 13 #include "ppapi/cpp/instance_handle.h" |
| 14 #include "ppapi/cpp/module.h" |
| 15 #include "ppapi/cpp/module_impl.h" |
| 16 #include "ppapi/cpp/var.h" |
| 17 |
| 18 namespace pp { |
| 19 |
| 20 namespace { |
| 21 |
| 22 template <> const char* interface_name<PPB_VideoReader_1_0>() { |
| 23 return PPB_VIDEOREADER_INTERFACE_1_0; |
| 24 } |
| 25 template <> const char* interface_name<PPB_VideoWriter_1_0>() { |
| 26 return PPB_VIDEOWRITER_INTERFACE_1_0; |
| 27 } |
| 28 |
| 29 } // namespace |
| 30 |
| 31 // VideoFrame ------------------------------------------------------------------ |
| 32 |
| 33 VideoFrame::VideoFrame() { |
| 34 video_frame_.image_data = image_data_.pp_resource(); |
| 35 set_timestamp(0); |
| 36 } |
| 37 |
| 38 VideoFrame::VideoFrame( |
| 39 PassRef, |
| 40 const PP_VideoFrame& pp_video_frame) { |
| 41 video_frame_ = pp_video_frame; |
| 42 image_data_ = ImageData(PASS_REF, pp_video_frame.image_data); |
| 43 } |
| 44 |
| 45 VideoFrame::VideoFrame(const VideoFrame& other) { |
| 46 set_image_data(other.image_data()); |
| 47 set_timestamp(other.timestamp()); |
| 48 } |
| 49 |
| 50 VideoFrame::~VideoFrame() { |
| 51 } |
| 52 |
| 53 VideoFrame& VideoFrame::operator=(const VideoFrame& other) { |
| 54 if (this == &other) |
| 55 return *this; |
| 56 |
| 57 set_image_data(other.image_data()); |
| 58 set_timestamp(other.timestamp()); |
| 59 |
| 60 return *this; |
| 61 } |
| 62 |
| 63 // VideoReader ----------------------------------------------------------------- |
| 64 |
| 65 VideoReader::VideoReader() { |
| 66 } |
| 67 |
| 68 VideoReader::VideoReader(const InstanceHandle& instance) { |
| 69 if (!has_interface<PPB_VideoReader_1_0>()) |
| 70 return; |
| 71 PassRefFromConstructor(get_interface<PPB_VideoReader_1_0>()->Create( |
| 72 instance.pp_instance())); |
| 73 } |
| 74 |
| 75 VideoReader::VideoReader(const VideoReader& other) |
| 76 : Resource(other) { |
| 77 } |
| 78 |
| 79 VideoReader::VideoReader(PassRef, PP_Resource resource) |
| 80 : Resource(PASS_REF, resource) { |
| 81 } |
| 82 |
| 83 int32_t VideoReader::Open(const Var& stream_id, |
| 84 const CompletionCallback& cc) { |
| 85 if (has_interface<PPB_VideoReader_1_0>()) { |
| 86 int32_t result = |
| 87 get_interface<PPB_VideoReader_1_0>()->Open( |
| 88 pp_resource(), |
| 89 stream_id.pp_var(), cc.pp_completion_callback()); |
| 90 return result; |
| 91 } |
| 92 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 93 } |
| 94 |
| 95 int32_t VideoReader::GetNextFrame( |
| 96 const CompletionCallbackWithOutput<VideoFrame>& cc) { |
| 97 if (has_interface<PPB_VideoReader_1_0>()) { |
| 98 return get_interface<PPB_VideoReader_1_0>()->GetNextFrame( |
| 99 pp_resource(), |
| 100 cc.output(), cc.pp_completion_callback()); |
| 101 } |
| 102 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 103 } |
| 104 |
| 105 void VideoReader::Close() { |
| 106 if (has_interface<PPB_VideoReader_1_0>()) { |
| 107 get_interface<PPB_VideoReader_1_0>()->Close(pp_resource()); |
| 108 } |
| 109 } |
| 110 |
| 111 // VideoWriter ----------------------------------------------------------------- |
| 112 |
| 113 VideoWriter::VideoWriter() { |
| 114 } |
| 115 |
| 116 VideoWriter::VideoWriter(const InstanceHandle& instance) { |
| 117 if (!has_interface<PPB_VideoWriter_1_0>()) |
| 118 return; |
| 119 PassRefFromConstructor(get_interface<PPB_VideoWriter_1_0>()->Create( |
| 120 instance.pp_instance())); |
| 121 } |
| 122 |
| 123 VideoWriter::VideoWriter(const VideoWriter& other) |
| 124 : Resource(other) { |
| 125 } |
| 126 |
| 127 VideoWriter::VideoWriter(PassRef, PP_Resource resource) |
| 128 : Resource(PASS_REF, resource) { |
| 129 } |
| 130 |
| 131 int32_t VideoWriter::Open(const Var& stream_id, |
| 132 const CompletionCallback& cc) { |
| 133 if (has_interface<PPB_VideoWriter_1_0>()) { |
| 134 int32_t result = |
| 135 get_interface<PPB_VideoWriter_1_0>()->Open( |
| 136 pp_resource(), |
| 137 stream_id.pp_var(), cc.pp_completion_callback()); |
| 138 return result; |
| 139 } |
| 140 return cc.MayForce(PP_ERROR_NOINTERFACE); |
| 141 } |
| 142 |
| 143 int32_t VideoWriter::PutNextFrame(const VideoFrame& frame) { |
| 144 if (has_interface<PPB_VideoWriter_1_0>()) { |
| 145 return get_interface<PPB_VideoWriter_1_0>()->PutNextFrame( |
| 146 pp_resource(), |
| 147 &frame.pp_video_frame()); |
| 148 } |
| 149 return PP_ERROR_NOINTERFACE; |
| 150 } |
| 151 |
| 152 void VideoWriter::Close() { |
| 153 if (has_interface<PPB_VideoWriter_1_0>()) { |
| 154 get_interface<PPB_VideoWriter_1_0>()->Close(pp_resource()); |
| 155 } |
| 156 } |
| 157 |
| 158 } // namespace pp |
OLD | NEW |