17dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Copyright 2013 The Chromium Authors. All rights reserved.
27dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Use of this source code is governed by a BSD-style license that can be
37dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// found in the LICENSE file.
47dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
57dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/bind.h"
69ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch#include "base/message_loop/message_loop.h"
77dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/synchronization/waitable_event.h"
87dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "base/threading/thread.h"
97dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "content/renderer/media/rtc_video_decoder.h"
107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "media/base/gmock_callback_support.h"
113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "media/filters/mock_gpu_video_accelerator_factories.h"
127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "media/video/mock_video_decode_accelerator.h"
137dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "testing/gtest/include/gtest/gtest.h"
147dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochusing ::testing::_;
167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochusing ::testing::Invoke;
177dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochusing ::testing::Return;
187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochusing ::testing::SaveArg;
197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochusing ::testing::WithArgs;
207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochnamespace content {
227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
23ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// TODO(wuchengli): add MockSharedMemroy so more functions can be tested.
247dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdochclass RTCVideoDecoderTest : public ::testing::Test,
257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                            webrtc::DecodedImageCallback {
267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch public:
277dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  RTCVideoDecoderTest()
283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      : mock_gpu_factories_(new media::MockGpuVideoAcceleratorFactories),
297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch        vda_thread_("vda_thread"),
307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch        idle_waiter_(false, false) {
317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    memset(&codec_, 0, sizeof(codec_));
327dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
347dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual void SetUp() OVERRIDE {
357dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    ASSERT_TRUE(vda_thread_.Start());
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    vda_task_runner_ = vda_thread_.message_loop_proxy();
377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    mock_vda_ = new media::MockVideoDecodeAccelerator;
381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    EXPECT_CALL(*mock_gpu_factories_.get(), GetTaskRunner())
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        .WillRepeatedly(Return(vda_task_runner_));
401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    EXPECT_CALL(*mock_gpu_factories_.get(), DoCreateVideoDecodeAccelerator())
41bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch        .WillRepeatedly(Return(mock_vda_));
421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    EXPECT_CALL(*mock_gpu_factories_.get(), CreateSharedMemory(_))
437dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch        .WillRepeatedly(Return(static_cast<base::SharedMemory*>(NULL)));
44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    EXPECT_CALL(*mock_vda_, Initialize(_, _))
45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        .Times(1)
46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)        .WillRepeatedly(Return(true));
47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    EXPECT_CALL(*mock_vda_, Destroy()).Times(1);
487dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
497dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual void TearDown() OVERRIDE {
517dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    VLOG(2) << "TearDown";
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    EXPECT_TRUE(vda_thread_.IsRunning());
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    RunUntilIdle();  // Wait until all callbascks complete.
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    vda_task_runner_->DeleteSoon(FROM_HERE, rtc_decoder_.release());
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    // Make sure the decoder is released before stopping the thread.
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    RunUntilIdle();
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    vda_thread_.Stop();
587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  virtual int32_t Decoded(webrtc::I420VideoFrame& decoded_image) OVERRIDE {
617dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    VLOG(2) << "Decoded";
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    EXPECT_EQ(vda_task_runner_, base::MessageLoopProxy::current());
637dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    return WEBRTC_VIDEO_CODEC_OK;
647dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
657dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
6603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  void CreateDecoder(webrtc::VideoCodecType codec_type) {
6703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    VLOG(2) << "CreateDecoder";
6803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    codec_.codecType = codec_type;
6903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)    rtc_decoder_ =
7003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)        RTCVideoDecoder::Create(codec_type, mock_gpu_factories_);
7103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  }
7203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
737dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  void Initialize() {
747dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    VLOG(2) << "Initialize";
757dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->InitDecode(&codec_, 1));
767dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK,
777dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch              rtc_decoder_->RegisterDecodeCompleteCallback(this));
787dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
797dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
807dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  void NotifyResetDone() {
817dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    VLOG(2) << "NotifyResetDone";
825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    vda_task_runner_->PostTask(
835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        FROM_HERE,
845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        base::Bind(&RTCVideoDecoder::NotifyResetDone,
855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                   base::Unretained(rtc_decoder_.get())));
867dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
877dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
887dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  void RunUntilIdle() {
897dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    VLOG(2) << "RunUntilIdle";
905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    vda_task_runner_->PostTask(FROM_HERE,
915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                               base::Bind(&base::WaitableEvent::Signal,
925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                          base::Unretained(&idle_waiter_)));
937dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch    idle_waiter_.Wait();
947dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  }
957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch protected:
973551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  scoped_refptr<media::MockGpuVideoAcceleratorFactories> mock_gpu_factories_;
987dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  media::MockVideoDecodeAccelerator* mock_vda_;
997dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  scoped_ptr<RTCVideoDecoder> rtc_decoder_;
1007dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  webrtc::VideoCodec codec_;
1017dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  base::Thread vda_thread_;
1027dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1037dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch private:
1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  scoped_refptr<base::SingleThreadTaskRunner> vda_task_runner_;
1057dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1067dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  base::Lock lock_;
1077dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  base::WaitableEvent idle_waiter_;
1087dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch};
1097dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
110bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben MurdochTEST_F(RTCVideoDecoderTest, CreateReturnsNullOnUnsupportedCodec) {
11103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  CreateDecoder(webrtc::kVideoCodecVP8);
112bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  scoped_ptr<RTCVideoDecoder> null_rtc_decoder(
113bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch      RTCVideoDecoder::Create(webrtc::kVideoCodecI420, mock_gpu_factories_));
114bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch  EXPECT_EQ(NULL, null_rtc_decoder.get());
115bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch}
116bbcdd45c55eb7c4641ab97aef9889b0fc828e7d3Ben Murdoch
11703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)TEST_F(RTCVideoDecoderTest, CreateAndInitSucceedsForH264Codec) {
11803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  CreateDecoder(webrtc::kVideoCodecH264);
11903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->InitDecode(&codec_, 1));
12003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)}
12103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
1227dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST_F(RTCVideoDecoderTest, InitDecodeReturnsErrorOnFeedbackMode) {
12303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  CreateDecoder(webrtc::kVideoCodecVP8);
1247dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  codec_.codecSpecific.VP8.feedbackModeOn = true;
1257dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR, rtc_decoder_->InitDecode(&codec_, 1));
1267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
1277dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1287dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST_F(RTCVideoDecoderTest, DecodeReturnsErrorWithoutInitDecode) {
12903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  CreateDecoder(webrtc::kVideoCodecVP8);
1307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  webrtc::EncodedImage input_image;
1317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_EQ(WEBRTC_VIDEO_CODEC_UNINITIALIZED,
1327dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch            rtc_decoder_->Decode(input_image, false, NULL, NULL, 0));
1337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
1347dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1357dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST_F(RTCVideoDecoderTest, DecodeReturnsErrorOnIncompleteFrame) {
13603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  CreateDecoder(webrtc::kVideoCodecVP8);
1377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  Initialize();
1387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  webrtc::EncodedImage input_image;
1397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  input_image._completeFrame = false;
1407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR,
1417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch            rtc_decoder_->Decode(input_image, false, NULL, NULL, 0));
1427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
1437dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1447dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST_F(RTCVideoDecoderTest, DecodeReturnsErrorOnMissingFrames) {
14503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  CreateDecoder(webrtc::kVideoCodecVP8);
1467dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  Initialize();
1477dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  webrtc::EncodedImage input_image;
1487dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  input_image._completeFrame = true;
1497dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  bool missingFrames = true;
1507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_EQ(WEBRTC_VIDEO_CODEC_ERROR,
1517dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch            rtc_decoder_->Decode(input_image, missingFrames, NULL, NULL, 0));
1527dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
1537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1547dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST_F(RTCVideoDecoderTest, ResetReturnsOk) {
15503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  CreateDecoder(webrtc::kVideoCodecVP8);
1567dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  Initialize();
1577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_CALL(*mock_vda_, Reset())
1587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      .WillOnce(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone));
1597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Reset());
1607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
1617dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1627dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST_F(RTCVideoDecoderTest, ReleaseReturnsOk) {
16303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  CreateDecoder(webrtc::kVideoCodecVP8);
1647dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  Initialize();
165ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_CALL(*mock_vda_, Reset())
166ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch      .WillOnce(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone));
167ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release());
168ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch}
169ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch
170ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben MurdochTEST_F(RTCVideoDecoderTest, InitDecodeAfterRelease) {
17103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  CreateDecoder(webrtc::kVideoCodecVP8);
172ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_CALL(*mock_vda_, Reset())
173ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch      .WillRepeatedly(Invoke(this, &RTCVideoDecoderTest::NotifyResetDone));
174ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  Initialize();
175ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release());
176ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  Initialize();
1777dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_EQ(WEBRTC_VIDEO_CODEC_OK, rtc_decoder_->Release());
1787dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
1797dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1807dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST_F(RTCVideoDecoderTest, IsBufferAfterReset) {
18103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  CreateDecoder(webrtc::kVideoCodecVP8);
1827dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_INVALID));
1837dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST,
1847dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                               RTCVideoDecoder::ID_INVALID));
1857dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_HALF - 2,
1867dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                                RTCVideoDecoder::ID_HALF + 2));
1877dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_HALF + 2,
1887dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                               RTCVideoDecoder::ID_HALF - 2));
1897dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1907dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(0, 0));
1917dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_LAST));
1927dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_FALSE(
1937dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_HALF - 2));
1947dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_TRUE(
1957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      rtc_decoder_->IsBufferAfterReset(0, RTCVideoDecoder::ID_HALF + 2));
1967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
1977dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST, 0));
1987dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST,
1997dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                                RTCVideoDecoder::ID_HALF - 2));
2007dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_TRUE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST,
2017dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                               RTCVideoDecoder::ID_HALF + 2));
2027dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  EXPECT_FALSE(rtc_decoder_->IsBufferAfterReset(RTCVideoDecoder::ID_LAST,
2037dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                                RTCVideoDecoder::ID_LAST));
2047dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}
2057dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
2063551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)TEST_F(RTCVideoDecoderTest, IsFirstBufferAfterReset) {
20703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  CreateDecoder(webrtc::kVideoCodecVP8);
2083551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_TRUE(
2093551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      rtc_decoder_->IsFirstBufferAfterReset(0, RTCVideoDecoder::ID_INVALID));
2103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_FALSE(
2113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      rtc_decoder_->IsFirstBufferAfterReset(1, RTCVideoDecoder::ID_INVALID));
2123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_FALSE(rtc_decoder_->IsFirstBufferAfterReset(0, 0));
2133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_TRUE(rtc_decoder_->IsFirstBufferAfterReset(1, 0));
2143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_FALSE(rtc_decoder_->IsFirstBufferAfterReset(2, 0));
2153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
2163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_FALSE(rtc_decoder_->IsFirstBufferAfterReset(RTCVideoDecoder::ID_HALF,
2173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                                     RTCVideoDecoder::ID_HALF));
2183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_TRUE(rtc_decoder_->IsFirstBufferAfterReset(
2193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      RTCVideoDecoder::ID_HALF + 1, RTCVideoDecoder::ID_HALF));
2203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_FALSE(rtc_decoder_->IsFirstBufferAfterReset(
2213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      RTCVideoDecoder::ID_HALF + 2, RTCVideoDecoder::ID_HALF));
2223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
2233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_FALSE(rtc_decoder_->IsFirstBufferAfterReset(RTCVideoDecoder::ID_LAST,
2243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                                     RTCVideoDecoder::ID_LAST));
2253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_TRUE(
2263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      rtc_decoder_->IsFirstBufferAfterReset(0, RTCVideoDecoder::ID_LAST));
2273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_FALSE(
2283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      rtc_decoder_->IsFirstBufferAfterReset(1, RTCVideoDecoder::ID_LAST));
2293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
2303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
2317dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch}  // content
232