1 // Copyright (c) 2012 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 "base/bind.h"
6 #include "base/logging.h"
7 #include "media/tools/player_x11/data_source_logger.h"
8
LogAndRunStopClosure(const base::Closure & closure)9 static void LogAndRunStopClosure(const base::Closure& closure) {
10 VLOG(1) << "Stop() finished";
11 closure.Run();
12 }
13
LogAndRunReadCB(int64 position,int size,const media::DataSource::ReadCB & read_cb,int result)14 static void LogAndRunReadCB(
15 int64 position, int size,
16 const media::DataSource::ReadCB& read_cb, int result) {
17 VLOG(1) << "Read(" << position << ", " << size << ") -> " << result;
18 read_cb.Run(result);
19 }
20
DataSourceLogger(scoped_ptr<media::DataSource> data_source,bool streaming)21 DataSourceLogger::DataSourceLogger(
22 scoped_ptr<media::DataSource> data_source,
23 bool streaming)
24 : data_source_(data_source.Pass()),
25 streaming_(streaming) {
26 }
27
set_host(media::DataSourceHost * host)28 void DataSourceLogger::set_host(media::DataSourceHost* host) {
29 VLOG(1) << "set_host(" << host << ")";
30 data_source_->set_host(host);
31 }
32
Stop(const base::Closure & closure)33 void DataSourceLogger::Stop(const base::Closure& closure) {
34 VLOG(1) << "Stop() started";
35 data_source_->Stop(base::Bind(&LogAndRunStopClosure, closure));
36 }
37
Read(int64 position,int size,uint8 * data,const media::DataSource::ReadCB & read_cb)38 void DataSourceLogger::Read(
39 int64 position, int size, uint8* data,
40 const media::DataSource::ReadCB& read_cb) {
41 VLOG(1) << "Read(" << position << ", " << size << ")";
42 data_source_->Read(position, size, data, base::Bind(
43 &LogAndRunReadCB, position, size, read_cb));
44 }
45
GetSize(int64 * size_out)46 bool DataSourceLogger::GetSize(int64* size_out) {
47 bool success = data_source_->GetSize(size_out);
48 VLOG(1) << "GetSize() -> " << (success ? "true" : "false")
49 << ", " << *size_out;
50 return success;
51 }
52
IsStreaming()53 bool DataSourceLogger::IsStreaming() {
54 if (streaming_) {
55 VLOG(1) << "IsStreaming() -> true (overridden)";
56 return true;
57 }
58
59 bool streaming = data_source_->IsStreaming();
60 VLOG(1) << "IsStreaming() -> " << (streaming ? "true" : "false");
61 return streaming;
62 }
63
SetBitrate(int bitrate)64 void DataSourceLogger::SetBitrate(int bitrate) {
65 VLOG(1) << "SetBitrate(" << bitrate << ")";
66 data_source_->SetBitrate(bitrate);
67 }
68
~DataSourceLogger()69 DataSourceLogger::~DataSourceLogger() {}
70