• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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/memory/scoped_ptr.h"
7 #include "base/test/simple_test_tick_clock.h"
8 #include "base/time/tick_clock.h"
9 #include "media/cast/cast_config.h"
10 #include "media/cast/cast_defines.h"
11 #include "media/cast/cast_environment.h"
12 #include "media/cast/cast_receiver.h"
13 #include "media/cast/test/fake_task_runner.h"
14 #include "media/cast/video_receiver/video_decoder.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 
17 namespace media {
18 namespace cast {
19 
20 using testing::_;
21 
22 // Random frame size for testing.
23 const int kFrameSize = 2345;
24 static const int64 kStartMillisecond = GG_INT64_C(1245);
25 
26 namespace {
27 class DecodeTestFrameCallback :
28   public base::RefCountedThreadSafe<DecodeTestFrameCallback> {
29  public:
DecodeTestFrameCallback()30   DecodeTestFrameCallback() {}
31 
DecodeComplete(const scoped_refptr<media::VideoFrame> & decoded_frame,const base::TimeTicks & render_time)32   void DecodeComplete(const scoped_refptr<media::VideoFrame>& decoded_frame,
33                       const base::TimeTicks& render_time) {}
34  protected:
~DecodeTestFrameCallback()35   virtual ~DecodeTestFrameCallback() {}
36  private:
37   friend class base::RefCountedThreadSafe<DecodeTestFrameCallback>;
38 };
39 }  // namespace
40 
41 class VideoDecoderTest : public ::testing::Test {
42  protected:
VideoDecoderTest()43   VideoDecoderTest()
44     : task_runner_(new test::FakeTaskRunner(&testing_clock_)),
45       cast_environment_(new CastEnvironment(&testing_clock_, task_runner_,
46           task_runner_, task_runner_, task_runner_, task_runner_,
47           GetDefaultCastLoggingConfig())),
48       test_callback_(new DecodeTestFrameCallback()) {
49     // Configure to vp8.
50     config_.codec = kVp8;
51     config_.use_external_decoder = false;
52     decoder_.reset(new VideoDecoder(config_, cast_environment_));
53     testing_clock_.Advance(
54         base::TimeDelta::FromMilliseconds(kStartMillisecond));
55   }
56 
~VideoDecoderTest()57   virtual ~VideoDecoderTest() {}
58 
59   scoped_ptr<VideoDecoder> decoder_;
60   VideoReceiverConfig config_;
61   base::SimpleTestTickClock testing_clock_;
62   scoped_refptr<test::FakeTaskRunner> task_runner_;
63   scoped_refptr<CastEnvironment> cast_environment_;
64   scoped_refptr<DecodeTestFrameCallback> test_callback_;
65 };
66 
67 // TODO(pwestin): EXPECT_DEATH tests can not pass valgrind.
TEST_F(VideoDecoderTest,DISABLED_SizeZero)68 TEST_F(VideoDecoderTest, DISABLED_SizeZero) {
69   EncodedVideoFrame encoded_frame;
70   base::TimeTicks render_time;
71   encoded_frame.codec = kVp8;
72   EXPECT_DEATH(
73       decoder_->DecodeVideoFrame(
74           &encoded_frame, render_time,
75           base::Bind(&DecodeTestFrameCallback::DecodeComplete, test_callback_)),
76       "Empty frame");
77 }
78 
79 // TODO(pwestin): EXPECT_DEATH tests can not pass valgrind.
TEST_F(VideoDecoderTest,DISABLED_InvalidCodec)80 TEST_F(VideoDecoderTest, DISABLED_InvalidCodec) {
81   EncodedVideoFrame encoded_frame;
82   base::TimeTicks render_time;
83   encoded_frame.data.assign(kFrameSize, 0);
84   encoded_frame.codec = kExternalVideo;
85   EXPECT_DEATH(
86       decoder_->DecodeVideoFrame(&encoded_frame, render_time, base::Bind(
87           &DecodeTestFrameCallback::DecodeComplete, test_callback_)),
88       "Invalid codec");
89 }
90 
91 // TODO(pwestin): Test decoding a real frame.
92 
93 }  // namespace cast
94 }  // namespace media
95