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

Side by Side Diff: examples/media_test/media_test.cc

Issue 2006093004: Motown: Convert MediaSink to expose MediaTimelineControlSite (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "examples/media_test/media_test.h" 5 #include "examples/media_test/media_test.h"
6 #include "mojo/public/cpp/application/connect.h" 6 #include "mojo/public/cpp/application/connect.h"
7 #include "mojo/services/media/common/cpp/timeline.h" 7 #include "mojo/services/media/common/cpp/timeline.h"
8 #include "mojo/services/media/common/cpp/timeline_function.h" 8 #include "mojo/services/media/common/cpp/timeline_function.h"
9 #include "mojo/services/media/control/interfaces/media_factory.mojom.h" 9 #include "mojo/services/media/control/interfaces/media_factory.mojom.h"
10 10
11 namespace mojo { 11 namespace mojo {
12 namespace media { 12 namespace media {
13 namespace examples { 13 namespace examples {
14 14
15 // static 15 // static
16 std::unique_ptr<MediaTest> MediaTest::Create( 16 std::unique_ptr<MediaTest> MediaTest::Create(
17 mojo::ApplicationImpl* app, 17 mojo::ApplicationImpl* app,
18 const std::string& input_file_name) { 18 const std::string& input_file_name) {
19 return std::unique_ptr<MediaTest>(new MediaTest(app, input_file_name)); 19 return std::unique_ptr<MediaTest>(new MediaTest(app, input_file_name));
20 } 20 }
21 21
22 MediaTest::MediaTest(mojo::ApplicationImpl* app, 22 MediaTest::MediaTest(mojo::ApplicationImpl* app,
23 const std::string& input_file_name) 23 const std::string& input_file_name) {
24 : state_(MediaState::UNPREPARED) {
25 MediaFactoryPtr factory; 24 MediaFactoryPtr factory;
26 ConnectToService(app->shell(), "mojo:media_factory", GetProxy(&factory)); 25 ConnectToService(app->shell(), "mojo:media_factory", GetProxy(&factory));
27 26
28 SeekingReaderPtr reader; 27 SeekingReaderPtr reader;
29 factory->CreateNetworkReader(input_file_name, GetProxy(&reader)); 28 factory->CreateNetworkReader(input_file_name, GetProxy(&reader));
30 factory->CreatePlayer(reader.Pass(), GetProxy(&media_player_)); 29 factory->CreatePlayer(reader.Pass(), GetProxy(&media_player_));
31 30
32 HandleStatusUpdates(); 31 HandleStatusUpdates();
33 } 32 }
34 33
(...skipping 15 matching lines...) Expand all
50 } 49 }
51 50
52 const MediaMetadataPtr& MediaTest::metadata() const { 51 const MediaMetadataPtr& MediaTest::metadata() const {
53 return metadata_; 52 return metadata_;
54 } 53 }
55 54
56 void MediaTest::HandleStatusUpdates(uint64_t version, 55 void MediaTest::HandleStatusUpdates(uint64_t version,
57 MediaPlayerStatusPtr status) { 56 MediaPlayerStatusPtr status) {
58 if (status) { 57 if (status) {
59 // Process status received from the player. 58 // Process status received from the player.
60 previous_state_ = state_;
61 state_ = status->state;
62
63 if (status->timeline_transform) { 59 if (status->timeline_transform) {
64 timeline_function_ = status->timeline_transform.To<TimelineFunction>(); 60 timeline_function_ = status->timeline_transform.To<TimelineFunction>();
65 } 61 }
66 62
63 previous_state_ = state_;
64 if (status->end_of_stream) {
65 state_ = State::kEnded;
66 } else if (timeline_function_.subject_delta() == 0) {
67 state_ = State::kPaused;
68 } else {
69 state_ = State::kPlaying;
70 }
71
67 metadata_ = status->metadata.Pass(); 72 metadata_ = status->metadata.Pass();
68 73
69 if (update_callback_ != nullptr) { 74 if (update_callback_ != nullptr) {
70 update_callback_(); 75 update_callback_();
71 } 76 }
72 } 77 }
73 78
74 // Request a status update. 79 // Request a status update.
75 media_player_->GetStatus( 80 media_player_->GetStatus(
76 version, [this](uint64_t version, MediaPlayerStatusPtr status) { 81 version, [this](uint64_t version, MediaPlayerStatusPtr status) {
77 HandleStatusUpdates(version, status.Pass()); 82 HandleStatusUpdates(version, status.Pass());
78 }); 83 });
79 } 84 }
80 85
81 } // namespace examples 86 } // namespace examples
82 } // namespace media 87 } // namespace media
83 } // namespace mojo 88 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698