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

Side by Side Diff: content/renderer/media/video_frame_deliverer.cc

Issue 264363005: Cast: deliver video frames on the IO thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ThreadCheckerImpl Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/media/video_frame_deliverer.h" 5 #include "content/renderer/media/video_frame_deliverer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 9
10 namespace content { 10 namespace content {
11 namespace {
12 void ResetCallback(scoped_ptr<VideoCaptureDeliverFrameCB> callback) {
13 // |callback| will be deleted when this exits.
14 }
15 } // namespace
11 16
12 VideoFrameDeliverer::VideoFrameDeliverer( 17 VideoFrameDeliverer::VideoFrameDeliverer(
13 const scoped_refptr<base::MessageLoopProxy>& io_message_loop) 18 const scoped_refptr<base::MessageLoopProxy>& io_message_loop)
14 : io_message_loop_(io_message_loop) { 19 : io_message_loop_(io_message_loop) {
15 DCHECK(io_message_loop_); 20 DCHECK(io_message_loop_);
16 } 21 }
17 22
18 VideoFrameDeliverer::~VideoFrameDeliverer() { 23 VideoFrameDeliverer::~VideoFrameDeliverer() {
19 DCHECK(callbacks_.empty()); 24 DCHECK(callbacks_.empty());
20 } 25 }
(...skipping 13 matching lines...) Expand all
34 const VideoCaptureDeliverFrameCB& callback) { 39 const VideoCaptureDeliverFrameCB& callback) {
35 DCHECK(io_message_loop_->BelongsToCurrentThread()); 40 DCHECK(io_message_loop_->BelongsToCurrentThread());
36 callbacks_.push_back(std::make_pair(id, callback)); 41 callbacks_.push_back(std::make_pair(id, callback));
37 } 42 }
38 43
39 void VideoFrameDeliverer::RemoveCallback(void* id) { 44 void VideoFrameDeliverer::RemoveCallback(void* id) {
40 DCHECK(thread_checker_.CalledOnValidThread()); 45 DCHECK(thread_checker_.CalledOnValidThread());
41 io_message_loop_->PostTask( 46 io_message_loop_->PostTask(
42 FROM_HERE, 47 FROM_HERE,
43 base::Bind(&VideoFrameDeliverer::RemoveCallbackOnIO, 48 base::Bind(&VideoFrameDeliverer::RemoveCallbackOnIO,
44 this, id)); 49 this, id, base::MessageLoopProxy::current()));
45 } 50 }
46 51
47 void VideoFrameDeliverer::RemoveCallbackOnIO(void* id) { 52 void VideoFrameDeliverer::RemoveCallbackOnIO(
53 void* id, const scoped_refptr<base::MessageLoopProxy>& message_loop) {
48 DCHECK(io_message_loop_->BelongsToCurrentThread()); 54 DCHECK(io_message_loop_->BelongsToCurrentThread());
49 std::vector<VideoIdCallbackPair>::iterator it = callbacks_.begin(); 55 std::vector<VideoIdCallbackPair>::iterator it = callbacks_.begin();
50 for (; it != callbacks_.end(); ++it) { 56 for (; it != callbacks_.end(); ++it) {
51 if (it->first == id) { 57 if (it->first == id) {
52 callbacks_.erase(it); 58 // Callback is copied to heap and then deleted on the target thread.
59 // The following code ensures that the callback is not referenced on
60 // the stack.
61 scoped_ptr<VideoCaptureDeliverFrameCB> callback;
62 {
63 callback.reset(new VideoCaptureDeliverFrameCB(it->second));
64 callbacks_.erase(it);
65 }
66 message_loop->PostTask(
67 FROM_HERE, base::Bind(&ResetCallback, base::Passed(&callback)));
53 return; 68 return;
54 } 69 }
55 } 70 }
56 } 71 }
57 72
58 void VideoFrameDeliverer::DeliverFrameOnIO( 73 void VideoFrameDeliverer::DeliverFrameOnIO(
59 const scoped_refptr<media::VideoFrame>& frame, 74 const scoped_refptr<media::VideoFrame>& frame,
60 const media::VideoCaptureFormat& format) { 75 const media::VideoCaptureFormat& format) {
61 DCHECK(io_message_loop_->BelongsToCurrentThread()); 76 DCHECK(io_message_loop_->BelongsToCurrentThread());
62 for (std::vector<VideoIdCallbackPair>::iterator it = callbacks_.begin(); 77 for (std::vector<VideoIdCallbackPair>::iterator it = callbacks_.begin();
63 it != callbacks_.end(); ++it) { 78 it != callbacks_.end(); ++it) {
64 it->second.Run(frame, format); 79 it->second.Run(frame, format);
65 } 80 }
66 } 81 }
67 82
68 } // namespace content 83 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/video_frame_deliverer.h ('k') | content/renderer/media/video_source_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698