mock_frame_consumer.h revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
1// Copyright 2014 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#ifndef CHROMECAST_MEDIA_CMA_BASE_MOCK_FRAME_CONSUMER_H_
6#define CHROMECAST_MEDIA_CMA_BASE_MOCK_FRAME_CONSUMER_H_
7
8#include <vector>
9
10#include "base/callback.h"
11#include "base/macros.h"
12
13namespace media {
14class AudioDecoderConfig;
15class VideoDecoderConfig;
16}
17
18namespace chromecast {
19namespace media {
20class CodedFrameProvider;
21class DecoderBufferBase;
22class FrameGeneratorForTest;
23
24class MockFrameConsumer {
25 public:
26  explicit MockFrameConsumer(CodedFrameProvider* coded_frame_provider);
27  ~MockFrameConsumer();
28
29  void Configure(const std::vector<bool>& delayed_task_pattern,
30                 bool last_read_aborted_by_flush,
31                 scoped_ptr<FrameGeneratorForTest> frame_generator);
32
33  // Starts consuming frames. Invoke |done_cb| when all the expected frames
34  // have been received.
35  void Start(const base::Closure& done_cb);
36
37 private:
38  void ReadFrame();
39  void OnNewFrame(const scoped_refptr<DecoderBufferBase>& buffer,
40                  const ::media::AudioDecoderConfig& audio_config,
41                  const ::media::VideoDecoderConfig& video_config);
42
43  void OnFlushCompleted();
44
45  CodedFrameProvider* const coded_frame_provider_;
46
47  base::Closure done_cb_;
48
49  // Parameterization of the frame consumer:
50  // |delayed_task_pattern_| indicates the pattern for fetching frames,
51  // i.e. after receiving a frame, either fetch a frame right away
52  // or wait some time before fetching another frame.
53  // |pattern_idx_| is the current index in the pattern.
54  // |last_read_aborted_by_flush_| indicates whether the last buffer request
55  // should be aborted by a Flush.
56  std::vector<bool> delayed_task_pattern_;
57  size_t pattern_idx_;
58  bool last_read_aborted_by_flush_;
59
60  // Expected results.
61  scoped_ptr<FrameGeneratorForTest> frame_generator_;
62
63  DISALLOW_COPY_AND_ASSIGN(MockFrameConsumer);
64};
65
66}  // namespace media
67}  // namespace chromecast
68
69#endif  // CHROMECAST_MEDIA_CMA_BASE_MOCK_FRAME_CONSUMER_H_
70