summaryrefslogtreecommitdiffstats
path: root/media/cast/test/utility/standalone_cast_environment.cc
blob: c9dcb0b9caf92c1d4247329c7c129d8c7a8063f4 (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
// Copyright 2014 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 "media/cast/test/utility/standalone_cast_environment.h"

#include "base/time/default_tick_clock.h"

namespace media {
namespace cast {

StandaloneCastEnvironment::StandaloneCastEnvironment()
    : CastEnvironment(
          make_scoped_ptr<base::TickClock>(new base::DefaultTickClock()),
          NULL,
          NULL,
          NULL),
      main_thread_("StandaloneCastEnvironment Main"),
      audio_thread_("StandaloneCastEnvironment Audio"),
      video_thread_("StandaloneCastEnvironment Video") {
#define CREATE_TASK_RUNNER(name, options)   \
  name##_thread_.StartWithOptions(options); \
  CastEnvironment::name##_thread_proxy_ = name##_thread_.message_loop_proxy()

  CREATE_TASK_RUNNER(main,
                     base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
  CREATE_TASK_RUNNER(audio, base::Thread::Options());
  CREATE_TASK_RUNNER(video, base::Thread::Options());
#undef CREATE_TASK_RUNNER
}

StandaloneCastEnvironment::~StandaloneCastEnvironment() {
  CHECK(CalledOnValidThread());
  CHECK(!main_thread_.IsRunning());
  CHECK(!audio_thread_.IsRunning());
  CHECK(!video_thread_.IsRunning());
}

void StandaloneCastEnvironment::Shutdown() {
  CHECK(CalledOnValidThread());
  main_thread_.Stop();
  audio_thread_.Stop();
  video_thread_.Stop();
}

}  // namespace cast
}  // namespace media