| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 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 | 
|  | 3 // found in the LICENSE file. | 
|  | 4 | 
|  | 5 #include "examples/media_test/media_test.h" | 
|  | 6 #include "mojo/services/media/common/cpp/linear_transform.h" | 
|  | 7 #include "mojo/services/media/common/cpp/local_time.h" | 
|  | 8 #include "mojo/services/media/control/interfaces/media_factory.mojom.h" | 
|  | 9 | 
|  | 10 namespace mojo { | 
|  | 11 namespace media { | 
|  | 12 namespace examples { | 
|  | 13 | 
|  | 14 // static | 
|  | 15 std::unique_ptr<MediaTest> MediaTest::Create( | 
|  | 16     mojo::ApplicationImpl* app, | 
|  | 17     const std::string& input_file_name) { | 
|  | 18   return std::unique_ptr<MediaTest>(new MediaTest(app, input_file_name)); | 
|  | 19 } | 
|  | 20 | 
|  | 21 MediaTest::MediaTest( | 
|  | 22     mojo::ApplicationImpl* app, | 
|  | 23     const std::string& input_file_name) : | 
|  | 24     state_(MediaState::UNPREPARED) { | 
|  | 25   MediaFactoryPtr factory; | 
|  | 26   app->ConnectToService("mojo:media_factory", &factory); | 
|  | 27 | 
|  | 28   factory->CreatePlayer(input_file_name, GetProxy(&media_player_)); | 
|  | 29 | 
|  | 30   HandleStatusUpdates(); | 
|  | 31 } | 
|  | 32 | 
|  | 33 MediaTest::~MediaTest() {} | 
|  | 34 | 
|  | 35 void MediaTest::RegisterUpdateCallback(const UpdateCallback& callback) { | 
|  | 36   update_callback_ = callback; | 
|  | 37 } | 
|  | 38 | 
|  | 39 void MediaTest::Play() { | 
|  | 40   media_player_->Play(); | 
|  | 41 } | 
|  | 42 | 
|  | 43 void MediaTest::Pause() { | 
|  | 44   media_player_->Pause(); | 
|  | 45 } | 
|  | 46 | 
|  | 47 void MediaTest::Seek(int64_t position_ns) { | 
|  | 48   media_player_->Seek(position_ns); | 
|  | 49 } | 
|  | 50 | 
|  | 51 MediaState MediaTest::state() const { | 
|  | 52   return state_; | 
|  | 53 } | 
|  | 54 | 
|  | 55 int64_t MediaTest::position_ns() const { | 
|  | 56   // Apply the transform to the current time. | 
|  | 57   int64_t position; | 
|  | 58   transform_.DoForwardTransform( | 
|  | 59       LocalClock::now().time_since_epoch().count(), | 
|  | 60       &position); | 
|  | 61 | 
|  | 62   MOJO_DCHECK(position >= 0); | 
|  | 63 | 
|  | 64   if (metadata_ && | 
|  | 65       static_cast<uint64_t>(position) > metadata_->duration) { | 
|  | 66     position = metadata_->duration; | 
|  | 67   } | 
|  | 68 | 
|  | 69   return position; | 
|  | 70 } | 
|  | 71 | 
|  | 72 const MediaMetadataPtr& MediaTest::metadata() const { | 
|  | 73   return metadata_; | 
|  | 74 } | 
|  | 75 | 
|  | 76 void MediaTest::HandleStatusUpdates( | 
|  | 77     uint64_t version, | 
|  | 78     MediaPlayerStatusPtr status) { | 
|  | 79   if (status) { | 
|  | 80     // Process status received from the player. | 
|  | 81     state_ = status->state; | 
|  | 82 | 
|  | 83     // Create a linear transform that translates local time to presentation | 
|  | 84     // time. Note that 'reference' here refers to the presentation time, and | 
|  | 85     // 'target' refers to the local time. | 
|  | 86     if (status->timeline_transform) { | 
|  | 87       transform_ = LinearTransform( | 
|  | 88           status->timeline_transform->quad->target_offset, | 
|  | 89           status->timeline_transform->quad->reference_delta, | 
|  | 90           status->timeline_transform->quad->target_delta, | 
|  | 91           status->timeline_transform->quad->reference_offset); | 
|  | 92     } | 
|  | 93 | 
|  | 94     metadata_ = status->metadata.Pass(); | 
|  | 95 | 
|  | 96     if (update_callback_ != nullptr) { | 
|  | 97       update_callback_(); | 
|  | 98     } | 
|  | 99   } | 
|  | 100 | 
|  | 101   // Request a status update. | 
|  | 102   media_player_->GetStatus( | 
|  | 103       version, | 
|  | 104       [this](uint64_t version, MediaPlayerStatusPtr status) { | 
|  | 105         HandleStatusUpdates(version, status.Pass()); | 
|  | 106       }); | 
|  | 107 } | 
|  | 108 | 
|  | 109 }  // namespace examples | 
|  | 110 }  // namespace media | 
|  | 111 }  // namespace mojo | 
| OLD | NEW | 
|---|