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

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

Issue 617093003: Add MediaStreamSource frame rate calculation to the tracker. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding type name. Fixing IPC type problem. Created 6 years, 2 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
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/media_stream_video_source.h" 5 #include "content/renderer/media/media_stream_video_source.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 10
11 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "content/child/child_process.h" 14 #include "content/child/child_process.h"
15 #include "content/renderer/render_thread_impl.h"
15 #include "content/renderer/media/media_stream_constraints_util.h" 16 #include "content/renderer/media/media_stream_constraints_util.h"
16 #include "content/renderer/media/media_stream_video_track.h" 17 #include "content/renderer/media/media_stream_video_track.h"
18 #include "content/renderer/media/peer_connection_tracker.h"
17 #include "content/renderer/media/video_track_adapter.h" 19 #include "content/renderer/media/video_track_adapter.h"
18 20
19 namespace content { 21 namespace content {
20 22
21 // Constraint keys. Specified by draft-alvestrand-constraints-resolution-00b 23 // Constraint keys. Specified by draft-alvestrand-constraints-resolution-00b
22 const char MediaStreamVideoSource::kMinAspectRatio[] = "minAspectRatio"; 24 const char MediaStreamVideoSource::kMinAspectRatio[] = "minAspectRatio";
23 const char MediaStreamVideoSource::kMaxAspectRatio[] = "maxAspectRatio"; 25 const char MediaStreamVideoSource::kMaxAspectRatio[] = "maxAspectRatio";
24 const char MediaStreamVideoSource::kMaxWidth[] = "maxWidth"; 26 const char MediaStreamVideoSource::kMaxWidth[] = "maxWidth";
25 const char MediaStreamVideoSource::kMinWidth[] = "minWidth"; 27 const char MediaStreamVideoSource::kMinWidth[] = "minWidth";
26 const char MediaStreamVideoSource::kMaxHeight[] = "maxHeight"; 28 const char MediaStreamVideoSource::kMaxHeight[] = "maxHeight";
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 MediaStreamVideoSource::io_message_loop() const { 453 MediaStreamVideoSource::io_message_loop() const {
452 DCHECK(CalledOnValidThread()); 454 DCHECK(CalledOnValidThread());
453 return track_adapter_->io_message_loop(); 455 return track_adapter_->io_message_loop();
454 } 456 }
455 457
456 void MediaStreamVideoSource::DoStopSource() { 458 void MediaStreamVideoSource::DoStopSource() {
457 DCHECK(CalledOnValidThread()); 459 DCHECK(CalledOnValidThread());
458 DVLOG(3) << "DoStopSource()"; 460 DVLOG(3) << "DoStopSource()";
459 if (state_ == ENDED) 461 if (state_ == ENDED)
460 return; 462 return;
461 track_adapter_->StopFrameMonitoring();
462 StopSourceImpl(); 463 StopSourceImpl();
463 state_ = ENDED; 464 state_ = ENDED;
464 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded); 465 SetReadyState(blink::WebMediaStreamSource::ReadyStateEnded);
465 } 466 }
466 467
467 void MediaStreamVideoSource::OnSupportedFormats( 468 void MediaStreamVideoSource::OnSupportedFormats(
468 const media::VideoCaptureFormats& formats) { 469 const media::VideoCaptureFormats& formats) {
469 DCHECK(CalledOnValidThread()); 470 DCHECK(CalledOnValidThread());
470 DCHECK_EQ(RETRIEVING_CAPABILITIES, state_); 471 DCHECK_EQ(RETRIEVING_CAPABILITIES, state_);
471 472
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 void MediaStreamVideoSource::OnStartDone(MediaStreamRequestResult result) { 523 void MediaStreamVideoSource::OnStartDone(MediaStreamRequestResult result) {
523 DCHECK(CalledOnValidThread()); 524 DCHECK(CalledOnValidThread());
524 DVLOG(3) << "OnStartDone({result =" << result << "})"; 525 DVLOG(3) << "OnStartDone({result =" << result << "})";
525 if (result == MEDIA_DEVICE_OK) { 526 if (result == MEDIA_DEVICE_OK) {
526 DCHECK_EQ(STARTING, state_); 527 DCHECK_EQ(STARTING, state_);
527 state_ = STARTED; 528 state_ = STARTED;
528 SetReadyState(blink::WebMediaStreamSource::ReadyStateLive); 529 SetReadyState(blink::WebMediaStreamSource::ReadyStateLive);
529 530
530 track_adapter_->StartFrameMonitoring( 531 track_adapter_->StartFrameMonitoring(
531 current_format_.frame_rate, 532 current_format_.frame_rate,
532 base::Bind(&MediaStreamVideoSource::SetMutedState, 533 base::Bind(&MediaStreamVideoSource::OnFrameRateCallback,
533 weak_factory_.GetWeakPtr())); 534 weak_factory_.GetWeakPtr()));
534 535
535 } else { 536 } else {
536 StopSource(); 537 StopSource();
537 } 538 }
538 539
539 // This object can be deleted after calling FinalizeAddTrack. See comment in 540 // This object can be deleted after calling FinalizeAddTrack. See comment in
540 // the header file. 541 // the header file.
541 FinalizeAddTrack(); 542 FinalizeAddTrack();
542 } 543 }
543 544
545 std::string MediaStreamVideoSource::TypeName() const {
546 return "";
547 }
548
544 void MediaStreamVideoSource::FinalizeAddTrack() { 549 void MediaStreamVideoSource::FinalizeAddTrack() {
545 DCHECK(CalledOnValidThread()); 550 DCHECK(CalledOnValidThread());
546 media::VideoCaptureFormats formats; 551 media::VideoCaptureFormats formats;
547 formats.push_back(current_format_); 552 formats.push_back(current_format_);
548 553
549 std::vector<RequestedConstraints> callbacks; 554 std::vector<RequestedConstraints> callbacks;
550 callbacks.swap(requested_constraints_); 555 callbacks.swap(requested_constraints_);
551 for (std::vector<RequestedConstraints>::iterator it = callbacks.begin(); 556 for (std::vector<RequestedConstraints>::iterator it = callbacks.begin();
552 it != callbacks.end(); ++it) { 557 it != callbacks.end(); ++it) {
553 MediaStreamRequestResult result = MEDIA_DEVICE_OK; 558 MediaStreamRequestResult result = MEDIA_DEVICE_OK;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 DVLOG(3) << "MediaStreamVideoSource::SetReadyState state " << state; 598 DVLOG(3) << "MediaStreamVideoSource::SetReadyState state " << state;
594 DCHECK(CalledOnValidThread()); 599 DCHECK(CalledOnValidThread());
595 if (!owner().isNull()) 600 if (!owner().isNull())
596 owner().setReadyState(state); 601 owner().setReadyState(state);
597 for (std::vector<MediaStreamVideoTrack*>::iterator it = tracks_.begin(); 602 for (std::vector<MediaStreamVideoTrack*>::iterator it = tracks_.begin();
598 it != tracks_.end(); ++it) { 603 it != tracks_.end(); ++it) {
599 (*it)->OnReadyStateChanged(state); 604 (*it)->OnReadyStateChanged(state);
600 } 605 }
601 } 606 }
602 607
603 void MediaStreamVideoSource::SetMutedState(bool muted_state) { 608 void MediaStreamVideoSource::OnFrameRateCallback(float framerate,
604 DVLOG(3) << "MediaStreamVideoSource::SetMutedState state=" << muted_state; 609 int dropped_frames) {
605 DCHECK(CalledOnValidThread()); 610 DCHECK(CalledOnValidThread());
606 if (!owner().isNull()) { 611 if (owner().isNull())
607 owner().setReadyState(muted_state 612 return;
608 ? blink::WebMediaStreamSource::ReadyStateMuted 613 if(owner().readyState() == blink::WebMediaStreamSource::ReadyStateEnded) {
609 : blink::WebMediaStreamSource::ReadyStateLive); 614 track_adapter_->StopFrameMonitoring();
615 return;
616 }
617
618 owner().setReadyState(framerate == 0
619 ? blink::WebMediaStreamSource::ReadyStateMuted
620 : blink::WebMediaStreamSource::ReadyStateLive);
621 const std::string id = TypeName() + " " + owner().name().utf8();
622 DVLOG(3) << "MediaStreamVideoSource::OnFrameRateCallback "
623 << id << " framerate="
624 << framerate << " dropped_frames=" << dropped_frames
625 << " readyState "<< owner().readyState();
626 if (RenderThreadImpl::current()) {
627 const std::string id = TypeName() + " " + owner().name().utf8();
628 RenderThreadImpl::current()->peer_connection_tracker()->TrackAddVideoStats(
629 id, framerate, dropped_frames);
610 } 630 }
611 } 631 }
612 632
613 MediaStreamVideoSource::RequestedConstraints::RequestedConstraints( 633 MediaStreamVideoSource::RequestedConstraints::RequestedConstraints(
614 MediaStreamVideoTrack* track, 634 MediaStreamVideoTrack* track,
615 const VideoCaptureDeliverFrameCB& frame_callback, 635 const VideoCaptureDeliverFrameCB& frame_callback,
616 const blink::WebMediaConstraints& constraints, 636 const blink::WebMediaConstraints& constraints,
617 const ConstraintsCallback& callback) 637 const ConstraintsCallback& callback)
618 : track(track), 638 : track(track),
619 frame_callback(frame_callback), 639 frame_callback(frame_callback),
620 constraints(constraints), 640 constraints(constraints),
621 callback(callback) { 641 callback(callback) {
622 } 642 }
623 643
624 MediaStreamVideoSource::RequestedConstraints::~RequestedConstraints() { 644 MediaStreamVideoSource::RequestedConstraints::~RequestedConstraints() {
625 } 645 }
626 646
627 } // namespace content 647 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/media_stream_video_source.h ('k') | content/renderer/media/mock_media_stream_video_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698