summaryrefslogtreecommitdiffstats
path: root/media/tools/player_x11/data_source_logger.cc
blob: d09b6bf2e1ac99651914042f35aaf9d32dd4de1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/bind.h"
#include "base/logging.h"
#include "media/tools/player_x11/data_source_logger.h"

static void LogAndRunReadCB(
    int64 position, int size,
    const media::DataSource::ReadCB& read_cb, int result) {
  VLOG(1) << "Read(" << position << ", " << size << ") -> " << result;
  read_cb.Run(result);
}

DataSourceLogger::DataSourceLogger(
    scoped_ptr<media::DataSource> data_source,
    bool streaming)
    : data_source_(data_source.Pass()),
      streaming_(streaming) {
}

void DataSourceLogger::Stop() {
  VLOG(1) << "Stop()";
  data_source_->Stop();
}

void DataSourceLogger::Read(
    int64 position, int size, uint8* data,
    const media::DataSource::ReadCB& read_cb) {
  VLOG(1) << "Read(" << position << ", " << size << ")";
  data_source_->Read(position, size, data, base::Bind(
      &LogAndRunReadCB, position, size, read_cb));
}

bool DataSourceLogger::GetSize(int64* size_out) {
  bool success = data_source_->GetSize(size_out);
  VLOG(1) << "GetSize() -> " << (success ? "true" : "false")
          << ", " << *size_out;
  return success;
}

bool DataSourceLogger::IsStreaming() {
  if (streaming_) {
    VLOG(1) << "IsStreaming() -> true (overridden)";
    return true;
  }

  bool streaming = data_source_->IsStreaming();
  VLOG(1) << "IsStreaming() -> " << (streaming ? "true" : "false");
  return streaming;
}

void DataSourceLogger::SetBitrate(int bitrate) {
  VLOG(1) << "SetBitrate(" << bitrate << ")";
  data_source_->SetBitrate(bitrate);
}

DataSourceLogger::~DataSourceLogger() {}