| Index: remoting/host/screen_recorder.cc
|
| diff --git a/remoting/host/screen_recorder.cc b/remoting/host/screen_recorder.cc
|
| index e332f278c257d4e7acdebb1106b40648e91e1ccf..de17940767b7496e48c6c46957c37ff82b353e47 100644
|
| --- a/remoting/host/screen_recorder.cc
|
| +++ b/remoting/host/screen_recorder.cc
|
| @@ -234,42 +234,30 @@ void ScreenRecorder::DoInvalidateFullScreen() {
|
|
|
| // Network thread --------------------------------------------------------------
|
|
|
| -void ScreenRecorder::DoSendVideoPacket(VideoPacket* packet) {
|
| +void ScreenRecorder::DoSendVideoPacket(scoped_ptr<VideoPacket> packet) {
|
| DCHECK(network_loop_->BelongsToCurrentThread());
|
|
|
| - bool last = (packet->flags() & VideoPacket::LAST_PARTITION) != 0;
|
| -
|
| - if (network_stopped_ || connections_.empty()) {
|
| - delete packet;
|
| + if (network_stopped_ || connections_.empty())
|
| return;
|
| - }
|
|
|
| - for (ConnectionToClientList::const_iterator i = connections_.begin();
|
| - i < connections_.end(); ++i) {
|
| - base::Closure done_task;
|
| -
|
| - // Call FrameSentCallback() only for the last packet in the first
|
| - // connection.
|
| - if (last && i == connections_.begin()) {
|
| - done_task = base::Bind(&ScreenRecorder::FrameSentCallback, this, packet);
|
| - } else {
|
| - // TODO(hclam): Fix this code since it causes multiple deletion if there's
|
| - // more than one connection.
|
| - done_task = base::Bind(&base::DeletePointer<VideoPacket>, packet);
|
| - }
|
| -
|
| - (*i)->video_stub()->ProcessVideoPacket(packet, done_task);
|
| - }
|
| + // TODO(sergeyu): Currently we send the data only to the first
|
| + // connection. Send it to all connections if necessary.
|
| + connections_.front()->video_stub()->ProcessVideoPacket(
|
| + packet.get(), base::Bind(
|
| + &ScreenRecorder::VideoPacketSentCallback, this,
|
| + base::Passed(packet.Pass())));
|
| }
|
|
|
| -void ScreenRecorder::FrameSentCallback(VideoPacket* packet) {
|
| - delete packet;
|
| -
|
| +void ScreenRecorder::VideoPacketSentCallback(scoped_ptr<VideoPacket> packet) {
|
| if (network_stopped_)
|
| return;
|
|
|
| - capture_loop_->PostTask(
|
| - FROM_HERE, base::Bind(&ScreenRecorder::DoFinishOneRecording, this));
|
| + if ((packet->flags() & VideoPacket::LAST_PARTITION) != 0) {
|
| + // Post DoFinishOneRecording() if that was the last packet for the
|
| + // frame.
|
| + capture_loop_->PostTask(
|
| + FROM_HERE, base::Bind(&ScreenRecorder::DoFinishOneRecording, this));
|
| + }
|
| }
|
|
|
| void ScreenRecorder::DoStopOnNetworkThread(const base::Closure& done_task) {
|
| @@ -297,11 +285,11 @@ void ScreenRecorder::DoEncode(
|
| // Early out if there's nothing to encode.
|
| if (!capture_data || capture_data->dirty_region().isEmpty()) {
|
| // Send an empty video packet to keep network active.
|
| - VideoPacket* packet = new VideoPacket();
|
| + scoped_ptr<VideoPacket> packet(new VideoPacket());
|
| packet->set_flags(VideoPacket::LAST_PARTITION);
|
| network_loop_->PostTask(
|
| FROM_HERE, base::Bind(&ScreenRecorder::DoSendVideoPacket,
|
| - this, packet));
|
| + this, base::Passed(packet.Pass())));
|
| return;
|
| }
|
|
|
| @@ -322,7 +310,8 @@ void ScreenRecorder::DoStopOnEncodeThread(const base::Closure& done_task) {
|
| capture_loop_->PostTask(FROM_HERE, done_task);
|
| }
|
|
|
| -void ScreenRecorder::EncodedDataAvailableCallback(VideoPacket* packet) {
|
| +void ScreenRecorder::EncodedDataAvailableCallback(
|
| + scoped_ptr<VideoPacket> packet) {
|
| DCHECK_EQ(encode_loop_, MessageLoop::current());
|
|
|
| if (encoder_stopped_)
|
| @@ -338,7 +327,8 @@ void ScreenRecorder::EncodedDataAvailableCallback(VideoPacket* packet) {
|
| }
|
|
|
| network_loop_->PostTask(
|
| - FROM_HERE, base::Bind(&ScreenRecorder::DoSendVideoPacket, this, packet));
|
| + FROM_HERE, base::Bind(&ScreenRecorder::DoSendVideoPacket, this,
|
| + base::Passed(packet.Pass())));
|
| }
|
|
|
| } // namespace remoting
|
|
|