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

Side by Side Diff: ppapi/shared_impl/media_stream_frame_buffer.h

Issue 128683003: [PPAPI] Implement media stream video track API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@video_track_impl_cl
Patch Set: Fix review issue Created 6 years, 11 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2014 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 #ifndef PPAPI_SHARED_IMPL_MEDIA_STREAM_FRAME_BUFFER_H_
6 #define PPAPI_SHARED_IMPL_MEDIA_STREAM_FRAME_BUFFER_H_
7
8 #include <deque>
9 #include <vector>
10
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/shared_memory.h"
14 #include "ppapi/shared_impl/media_stream_frame.h"
15 #include "ppapi/shared_impl/ppapi_shared_export.h"
16
17 namespace ppapi {
18
19 // This class is used by both read side and write side of a MediaStreamTrack to
20 // maintian a queue of frames for reading or writing.
yzshen1 2014/01/10 21:05:17 nit: maint*ai*n
Peng 2014/01/10 22:46:58 Done.
21 //
22 // An example:
23 // 1. The writer calls the writer's |frame_buffer_.Dequeue()| to get a free
24 // frame.
25 // 2. The writer fills data into the frame.
26 // 3. The writer sends the frame index to the reader via an IPC message.
27 // 4. The reader receiveds the frame index and calls the reader's
yzshen1 2014/01/10 21:05:17 nit: receive*s*
Peng 2014/01/10 22:46:58 Done.
28 // |frame_buffer.Enqueue()| to put the frame into the read's queue.
29 // 5. The reader calls reader's |frame_buffer_.Dequeue()| to get a received
30 // frame.
31 // 6. When the frame from the step 5 is consumed, the reader sends the frame
32 // index back to writer via an IPC message.
33 // 7. The writer receives the frame index and put it back to the writer's free
yzshen1 2014/01/10 21:05:17 put*s*
Peng 2014/01/10 22:46:58 Done.
34 // frame queue by calling the writer's |frame_buffer_.Enqueue()|.
35 // 8. Go back to step 1.
36 class PPAPI_SHARED_EXPORT MediaStreamFrameBuffer {
37 public:
38 class Delegate {
39 public:
yzshen1 2014/01/10 21:05:17 Please consider adding a virtual destructor.
Peng 2014/01/10 22:46:58 Done.
40 // It is called when a new frame is enqueued.
41 virtual void OnNewFrameEnqueued();
42 };
43
44 // MediaStreamFrameBuffer doesn't own |delegate|, the caller should keep
45 // it alive during the MediaStreamFrameBuffer's lifecycle.
46 explicit MediaStreamFrameBuffer(Delegate* delegate);
47
48 ~MediaStreamFrameBuffer();
49
50 int32_t number_of_frames() const { return number_of_frames_; }
51
52 int32_t frame_size() const { return frame_size_; }
53
54 // Initializes shared memory for frames transmission.
55 bool SetFrames(int32_t number_of_frames,
56 int32_t frame_size,
57 scoped_ptr<base::SharedMemory> shm,
58 bool enqueue_all_frames);
59
60 // Dequeues a frame from |frame_queue_|.
61 int32_t DequeueFrame();
62
63 // Puts a frame into |frame_queue_|.
64 void EnqueueFrame(int32_t index);
65
66 // Gets the frame address for the given frame index.
67 MediaStreamFrame* GetFramePointer(int32_t index);
68
69 private:
70 Delegate* delegate_;
71
72 // A queue of frame indexes.
73 std::deque<int32_t> frame_queue_;
74
75 // A vector of frame pointers. It is used for index to pointer converting.
76 std::vector<MediaStreamFrame*> frames_;
77
78 // The frame size in bytes.
79 int32_t frame_size_;
80
81 // The number of frames in the shared memory.
82 int32_t number_of_frames_;
83
84 // A memory block shared between renderer process and plugin process.
85 scoped_ptr<base::SharedMemory> shm_;
86
87 DISALLOW_COPY_AND_ASSIGN(MediaStreamFrameBuffer);
88 };
89
90 } // namespace ppapi
91
92 #endif // PPAPI_SHAERD_IMPL_MEDIA_STREAM_FRAME_BUFFER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698