Upstream version 10.38.208.0
[platform/framework/web/crosswalk.git] / src / content / common / gpu / media / video_decode_accelerator_unittest.cc
index c88385c..65cc939 100644 (file)
@@ -57,7 +57,7 @@
 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
 #include "content/common/gpu/media/v4l2_video_decode_accelerator.h"
 #include "content/common/gpu/media/v4l2_video_device.h"
-#elif (defined(OS_CHROMEOS) || defined(OS_LINUX)) && defined(ARCH_CPU_X86_FAMILY)
+#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
 #include "content/common/gpu/media/vaapi_video_decode_accelerator.h"
 #include "content/common/gpu/media/vaapi_wrapper.h"
 #if defined(USE_X11)
@@ -99,10 +99,7 @@ const base::FilePath::CharType* g_test_video_data =
 const base::FilePath::CharType* g_output_log = NULL;
 
 // The value is set by the switch "--rendering_fps".
-double g_rendering_fps = 0;
-
-// Disable rendering, the value is set by the switch "--disable_rendering".
-bool g_disable_rendering = false;
+double g_rendering_fps = 60;
 
 // Magic constants for differentiating the reasons for NotifyResetDone being
 // called.
@@ -145,10 +142,6 @@ struct TestVideoFile {
   std::string data_str;
 };
 
-// Presumed minimal display size.
-// We subtract one pixel from the width because some ARM chromebooks do not
-// support two fullscreen app running at the same time. See crbug.com/270064.
-const gfx::Size kThumbnailsDisplaySize(1366 - 1, 768);
 const gfx::Size kThumbnailsPageSize(1600, 1200);
 const gfx::Size kThumbnailSize(160, 120);
 const int kMD5StringLength = 32;
@@ -196,163 +189,14 @@ enum ClientState {
   CS_MAX,  // Must be last entry.
 };
 
-// A wrapper client that throttles the PictureReady callbacks to a given rate.
-// It may drops or queues frame to deliver them on time.
-class ThrottlingVDAClient : public VideoDecodeAccelerator::Client,
-                            public base::SupportsWeakPtr<ThrottlingVDAClient> {
- public:
-  // Callback invoked whan the picture is dropped and should be reused for
-  // the decoder again.
-  typedef base::Callback<void(int32 picture_buffer_id)> ReusePictureCB;
-
-  ThrottlingVDAClient(VideoDecodeAccelerator::Client* client,
-                      double fps,
-                      ReusePictureCB reuse_picture_cb);
-  virtual ~ThrottlingVDAClient();
-
-  // VideoDecodeAccelerator::Client implementation
-  virtual void ProvidePictureBuffers(uint32 requested_num_of_buffers,
-                                     const gfx::Size& dimensions,
-                                     uint32 texture_target) OVERRIDE;
-  virtual void DismissPictureBuffer(int32 picture_buffer_id) OVERRIDE;
-  virtual void PictureReady(const media::Picture& picture) OVERRIDE;
-  virtual void NotifyInitializeDone() OVERRIDE;
-  virtual void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id) OVERRIDE;
-  virtual void NotifyFlushDone() OVERRIDE;
-  virtual void NotifyResetDone() OVERRIDE;
-  virtual void NotifyError(VideoDecodeAccelerator::Error error) OVERRIDE;
-
-  int num_decoded_frames() { return num_decoded_frames_; }
-
- private:
-
-  void CallClientPictureReady(int version);
-
-  VideoDecodeAccelerator::Client* client_;
-  ReusePictureCB reuse_picture_cb_;
-  base::TimeTicks next_frame_delivered_time_;
-  base::TimeDelta frame_duration_;
-
-  int num_decoded_frames_;
-  int stream_version_;
-  std::deque<media::Picture> pending_pictures_;
-
-  DISALLOW_IMPLICIT_CONSTRUCTORS(ThrottlingVDAClient);
-};
-
-ThrottlingVDAClient::ThrottlingVDAClient(VideoDecodeAccelerator::Client* client,
-                                         double fps,
-                                         ReusePictureCB reuse_picture_cb)
-    : client_(client),
-      reuse_picture_cb_(reuse_picture_cb),
-      num_decoded_frames_(0),
-      stream_version_(0) {
-  CHECK(client_);
-  CHECK_GT(fps, 0);
-  frame_duration_ = base::TimeDelta::FromSeconds(1) / fps;
-}
-
-ThrottlingVDAClient::~ThrottlingVDAClient() {}
-
-void ThrottlingVDAClient::ProvidePictureBuffers(uint32 requested_num_of_buffers,
-                                                const gfx::Size& dimensions,
-                                                uint32 texture_target) {
-  client_->ProvidePictureBuffers(
-      requested_num_of_buffers, dimensions, texture_target);
-}
-
-void ThrottlingVDAClient::DismissPictureBuffer(int32 picture_buffer_id) {
-  client_->DismissPictureBuffer(picture_buffer_id);
-}
-
-void ThrottlingVDAClient::PictureReady(const media::Picture& picture) {
-  ++num_decoded_frames_;
-
-  if (pending_pictures_.empty()) {
-    base::TimeDelta delay =
-        next_frame_delivered_time_.is_null()
-            ? base::TimeDelta()
-            : next_frame_delivered_time_ - base::TimeTicks::Now();
-    base::MessageLoop::current()->PostDelayedTask(
-        FROM_HERE,
-        base::Bind(&ThrottlingVDAClient::CallClientPictureReady,
-                   AsWeakPtr(),
-                   stream_version_),
-        delay);
-  }
-  pending_pictures_.push_back(picture);
-}
-
-void ThrottlingVDAClient::CallClientPictureReady(int version) {
-  // Just return if we have reset the decoder
-  if (version != stream_version_)
-    return;
-
-  base::TimeTicks now = base::TimeTicks::Now();
-
-  if (next_frame_delivered_time_.is_null())
-    next_frame_delivered_time_ = now;
-
-  if (next_frame_delivered_time_ + frame_duration_ < now) {
-    // Too late, drop the frame
-    reuse_picture_cb_.Run(pending_pictures_.front().picture_buffer_id());
-  } else {
-    client_->PictureReady(pending_pictures_.front());
-  }
-
-  pending_pictures_.pop_front();
-  next_frame_delivered_time_ += frame_duration_;
-  if (!pending_pictures_.empty()) {
-    base::MessageLoop::current()->PostDelayedTask(
-        FROM_HERE,
-        base::Bind(&ThrottlingVDAClient::CallClientPictureReady,
-                   AsWeakPtr(),
-                   stream_version_),
-        next_frame_delivered_time_ - base::TimeTicks::Now());
-  }
-}
-
-void ThrottlingVDAClient::NotifyInitializeDone() {
-  client_->NotifyInitializeDone();
-}
-
-void ThrottlingVDAClient::NotifyEndOfBitstreamBuffer(
-    int32 bitstream_buffer_id) {
-  client_->NotifyEndOfBitstreamBuffer(bitstream_buffer_id);
-}
-
-void ThrottlingVDAClient::NotifyFlushDone() {
-  if (!pending_pictures_.empty()) {
-    base::MessageLoop::current()->PostDelayedTask(
-        FROM_HERE,
-        base::Bind(&ThrottlingVDAClient::NotifyFlushDone,
-                   base::Unretained(this)),
-        next_frame_delivered_time_ - base::TimeTicks::Now());
-    return;
-  }
-  client_->NotifyFlushDone();
-}
-
-void ThrottlingVDAClient::NotifyResetDone() {
-  ++stream_version_;
-  while (!pending_pictures_.empty()) {
-    reuse_picture_cb_.Run(pending_pictures_.front().picture_buffer_id());
-    pending_pictures_.pop_front();
-  }
-  next_frame_delivered_time_ = base::TimeTicks();
-  client_->NotifyResetDone();
-}
-
-void ThrottlingVDAClient::NotifyError(VideoDecodeAccelerator::Error error) {
-  client_->NotifyError(error);
-}
-
 // Client that can accept callbacks from a VideoDecodeAccelerator and is used by
 // the TESTs below.
 class GLRenderingVDAClient
     : public VideoDecodeAccelerator::Client,
       public base::SupportsWeakPtr<GLRenderingVDAClient> {
  public:
+  // |window_id| the window_id of the client, which is used to identify the
+  // rendering area in the |rendering_helper|.
   // Doesn't take ownership of |rendering_helper| or |note|, which must outlive
   // |*this|.
   // |num_play_throughs| indicates how many times to play through the video.
@@ -364,15 +208,13 @@ class GLRenderingVDAClient
   // calls have been made, N>=0 means interpret as ClientState.
   // Both |reset_after_frame_num| & |delete_decoder_state| apply only to the
   // last play-through (governed by |num_play_throughs|).
-  // |rendering_fps| indicates the target rendering fps. 0 means no target fps
-  // and it would render as fast as possible.
-  // |suppress_rendering| indicates GL rendering is suppressed or not.
+  // |suppress_rendering| indicates GL rendering is supressed or not.
   // After |delay_reuse_after_frame_num| frame has been delivered, the client
   // will start delaying the call to ReusePictureBuffer() for kReuseDelay.
   // |decode_calls_per_second| is the number of VDA::Decode calls per second.
   // If |decode_calls_per_second| > 0, |num_in_flight_decodes| must be 1.
-  GLRenderingVDAClient(RenderingHelper* rendering_helper,
-                       int rendering_window_id,
+  GLRenderingVDAClient(size_t window_id,
+                       RenderingHelper* rendering_helper,
                        ClientStateNotification<ClientState>* note,
                        const std::string& encoded_data,
                        int num_in_flight_decodes,
@@ -382,10 +224,10 @@ class GLRenderingVDAClient
                        int frame_width,
                        int frame_height,
                        media::VideoCodecProfile profile,
-                       double rendering_fps,
                        bool suppress_rendering,
                        int delay_reuse_after_frame_num,
-                       int decode_calls_per_second);
+                       int decode_calls_per_second,
+                       bool render_as_thumbnails);
   virtual ~GLRenderingVDAClient();
   void CreateAndStartDecoder();
 
@@ -397,7 +239,6 @@ class GLRenderingVDAClient
   virtual void DismissPictureBuffer(int32 picture_buffer_id) OVERRIDE;
   virtual void PictureReady(const media::Picture& picture) OVERRIDE;
   // Simple state changes.
-  virtual void NotifyInitializeDone() OVERRIDE;
   virtual void NotifyEndOfBitstreamBuffer(int32 bitstream_buffer_id) OVERRIDE;
   virtual void NotifyFlushDone() OVERRIDE;
   virtual void NotifyResetDone() OVERRIDE;
@@ -405,22 +246,22 @@ class GLRenderingVDAClient
 
   void OutputFrameDeliveryTimes(base::File* output);
 
-  void NotifyFrameDropped(int32 picture_buffer_id);
-
   // Simple getters for inspecting the state of the Client.
   int num_done_bitstream_buffers() { return num_done_bitstream_buffers_; }
   int num_skipped_fragments() { return num_skipped_fragments_; }
   int num_queued_fragments() { return num_queued_fragments_; }
-  int num_decoded_frames();
+  int num_decoded_frames() { return num_decoded_frames_; }
   double frames_per_second();
-  // Return the median of the decode time in milliseconds.
-  int decode_time_median();
+  // Return the median of the decode time of all decoded frames.
+  base::TimeDelta decode_time_median();
   bool decoder_deleted() { return !decoder_.get(); }
 
  private:
   typedef std::map<int, media::PictureBuffer*> PictureBufferById;
 
   void SetState(ClientState new_state);
+  void FinishInitialization();
+  void ReturnPicture(int32 picture_buffer_id);
 
   // Delete the associated decoder helper.
   void DeleteDecoder();
@@ -440,8 +281,9 @@ class GLRenderingVDAClient
   // Request decode of the next fragment in the encoded data.
   void DecodeNextFragment();
 
+  size_t window_id_;
   RenderingHelper* rendering_helper_;
-  int rendering_window_id_;
+  gfx::Size frame_size_;
   std::string encoded_data_;
   const int num_in_flight_decodes_;
   int outstanding_decodes_;
@@ -449,6 +291,8 @@ class GLRenderingVDAClient
   int next_bitstream_buffer_id_;
   ClientStateNotification<ClientState>* note_;
   scoped_ptr<VideoDecodeAccelerator> decoder_;
+  scoped_ptr<base::WeakPtrFactory<VideoDecodeAccelerator> >
+      weak_decoder_factory_;
   std::set<int> outstanding_texture_ids_;
   int remaining_play_throughs_;
   int reset_after_frame_num_;
@@ -465,20 +309,20 @@ class GLRenderingVDAClient
   bool suppress_rendering_;
   std::vector<base::TimeTicks> frame_delivery_times_;
   int delay_reuse_after_frame_num_;
-  scoped_ptr<ThrottlingVDAClient> throttling_client_;
   // A map from bitstream buffer id to the decode start time of the buffer.
   std::map<int, base::TimeTicks> decode_start_time_;
   // The decode time of all decoded frames.
   std::vector<base::TimeDelta> decode_time_;
   // The number of VDA::Decode calls per second. This is to simulate webrtc.
   int decode_calls_per_second_;
+  bool render_as_thumbnails_;
 
   DISALLOW_IMPLICIT_CONSTRUCTORS(GLRenderingVDAClient);
 };
 
 GLRenderingVDAClient::GLRenderingVDAClient(
+    size_t window_id,
     RenderingHelper* rendering_helper,
-    int rendering_window_id,
     ClientStateNotification<ClientState>* note,
     const std::string& encoded_data,
     int num_in_flight_decodes,
@@ -488,12 +332,13 @@ GLRenderingVDAClient::GLRenderingVDAClient(
     int frame_width,
     int frame_height,
     media::VideoCodecProfile profile,
-    double rendering_fps,
     bool suppress_rendering,
     int delay_reuse_after_frame_num,
-    int decode_calls_per_second)
-    : rendering_helper_(rendering_helper),
-      rendering_window_id_(rendering_window_id),
+    int decode_calls_per_second,
+    bool render_as_thumbnails)
+    : window_id_(window_id),
+      rendering_helper_(rendering_helper),
+      frame_size_(frame_width, frame_height),
       encoded_data_(encoded_data),
       num_in_flight_decodes_(num_in_flight_decodes),
       outstanding_decodes_(0),
@@ -511,10 +356,10 @@ GLRenderingVDAClient::GLRenderingVDAClient(
       texture_target_(0),
       suppress_rendering_(suppress_rendering),
       delay_reuse_after_frame_num_(delay_reuse_after_frame_num),
-      decode_calls_per_second_(decode_calls_per_second) {
+      decode_calls_per_second_(decode_calls_per_second),
+      render_as_thumbnails_(render_as_thumbnails) {
   CHECK_GT(num_in_flight_decodes, 0);
   CHECK_GT(num_play_throughs, 0);
-  CHECK_GE(rendering_fps, 0);
   // |num_in_flight_decodes_| is unsupported if |decode_calls_per_second_| > 0.
   if (decode_calls_per_second_ > 0)
     CHECK_EQ(1, num_in_flight_decodes_);
@@ -523,13 +368,6 @@ GLRenderingVDAClient::GLRenderingVDAClient(
   profile_ = (profile != media::VIDEO_CODEC_PROFILE_UNKNOWN
                   ? profile
                   : media::H264PROFILE_BASELINE);
-
-  if (rendering_fps > 0)
-    throttling_client_.reset(new ThrottlingVDAClient(
-        this,
-        rendering_fps,
-        base::Bind(&GLRenderingVDAClient::NotifyFrameDropped,
-                   base::Unretained(this))));
 }
 
 GLRenderingVDAClient::~GLRenderingVDAClient() {
@@ -547,27 +385,24 @@ void GLRenderingVDAClient::CreateAndStartDecoder() {
 
   VideoDecodeAccelerator::Client* client = this;
   base::WeakPtr<VideoDecodeAccelerator::Client> weak_client = AsWeakPtr();
-  if (throttling_client_) {
-    client = throttling_client_.get();
-    weak_client = throttling_client_->AsWeakPtr();
-  }
 #if defined(OS_WIN)
   decoder_.reset(
       new DXVAVideoDecodeAccelerator(base::Bind(&DoNothingReturnTrue)));
 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
 
-  scoped_ptr<V4L2Device> device = V4L2Device::Create();
+  scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kDecoder);
   if (!device.get()) {
     NotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE);
     return;
   }
   decoder_.reset(new V4L2VideoDecodeAccelerator(
       static_cast<EGLDisplay>(rendering_helper_->GetGLDisplay()),
+      static_cast<EGLContext>(rendering_helper_->GetGLContext()),
       weak_client,
       base::Bind(&DoNothingReturnTrue),
       device.Pass(),
       base::MessageLoopProxy::current()));
-#elif (defined(OS_CHROMEOS) || defined(OS_LINUX)) && defined(ARCH_CPU_X86_FAMILY)
+#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
   CHECK_EQ(gfx::kGLImplementationDesktopGL, gfx::GetGLImplementation())
       << "Hardware video decode does not work with OSMesa";
   decoder_.reset(new VaapiVideoDecodeAccelerator(
@@ -575,11 +410,14 @@ void GLRenderingVDAClient::CreateAndStartDecoder() {
       base::Bind(&DoNothingReturnTrue)));
 #endif  // OS_WIN
   CHECK(decoder_.get());
+  weak_decoder_factory_.reset(
+      new base::WeakPtrFactory<VideoDecodeAccelerator>(decoder_.get()));
   SetState(CS_DECODER_SET);
   if (decoder_deleted())
     return;
 
   CHECK(decoder_->Initialize(profile_, client));
+  FinishInitialization();
 }
 
 void GLRenderingVDAClient::ProvidePictureBuffers(
@@ -596,7 +434,7 @@ void GLRenderingVDAClient::ProvidePictureBuffers(
     uint32 texture_id;
     base::WaitableEvent done(false, false);
     rendering_helper_->CreateTexture(
-        rendering_window_id_, texture_target_, &texture_id, &done);
+        texture_target_, &texture_id, dimensions, &done);
     done.Wait();
     CHECK(outstanding_texture_ids_.insert(texture_id).second);
     media::PictureBuffer* buffer =
@@ -625,7 +463,9 @@ void GLRenderingVDAClient::PictureReady(const media::Picture& picture) {
     return;
 
   base::TimeTicks now = base::TimeTicks::Now();
+
   frame_delivery_times_.push_back(now);
+
   // Save the decode time of this picture.
   std::map<int, base::TimeTicks>::iterator it =
       decode_start_time_.find(picture.bitstream_buffer_id());
@@ -639,7 +479,7 @@ void GLRenderingVDAClient::PictureReady(const media::Picture& picture) {
   // Mid-stream reset applies only to the last play-through per constructor
   // comment.
   if (remaining_play_throughs_ == 1 &&
-      reset_after_frame_num_ == num_decoded_frames()) {
+      reset_after_frame_num_ == num_decoded_frames_) {
     reset_after_frame_num_ = MID_STREAM_RESET;
     decoder_->Reset();
     // Re-start decoding from the beginning of the stream to avoid needing to
@@ -650,38 +490,37 @@ void GLRenderingVDAClient::PictureReady(const media::Picture& picture) {
   media::PictureBuffer* picture_buffer =
       picture_buffers_by_id_[picture.picture_buffer_id()];
   CHECK(picture_buffer);
-  if (!suppress_rendering_) {
-    rendering_helper_->RenderTexture(texture_target_,
-                                     picture_buffer->texture_id());
+
+  scoped_refptr<VideoFrameTexture> video_frame =
+      new VideoFrameTexture(texture_target_,
+                            picture_buffer->texture_id(),
+                            base::Bind(&GLRenderingVDAClient::ReturnPicture,
+                                       AsWeakPtr(),
+                                       picture.picture_buffer_id()));
+
+  if (render_as_thumbnails_) {
+    rendering_helper_->RenderThumbnail(video_frame->texture_target(),
+                                       video_frame->texture_id());
+  } else if (!suppress_rendering_) {
+    rendering_helper_->QueueVideoFrame(window_id_, video_frame);
   }
+}
 
-  if (num_decoded_frames() > delay_reuse_after_frame_num_) {
+void GLRenderingVDAClient::ReturnPicture(int32 picture_buffer_id) {
+  if (decoder_deleted())
+    return;
+  if (num_decoded_frames_ > delay_reuse_after_frame_num_) {
     base::MessageLoop::current()->PostDelayedTask(
         FROM_HERE,
         base::Bind(&VideoDecodeAccelerator::ReusePictureBuffer,
-                   decoder_->AsWeakPtr(),
-                   picture.picture_buffer_id()),
+                   weak_decoder_factory_->GetWeakPtr(),
+                   picture_buffer_id),
         kReuseDelay);
   } else {
-    decoder_->ReusePictureBuffer(picture.picture_buffer_id());
+    decoder_->ReusePictureBuffer(picture_buffer_id);
   }
 }
 
-void GLRenderingVDAClient::NotifyInitializeDone() {
-  SetState(CS_INITIALIZED);
-  initialize_done_ticks_ = base::TimeTicks::Now();
-
-  if (reset_after_frame_num_ == START_OF_STREAM_RESET) {
-    reset_after_frame_num_ = MID_STREAM_RESET;
-    decoder_->Reset();
-    return;
-  }
-
-  for (int i = 0; i < num_in_flight_decodes_; ++i)
-    DecodeNextFragment();
-  DCHECK_EQ(outstanding_decodes_, num_in_flight_decodes_);
-}
-
 void GLRenderingVDAClient::NotifyEndOfBitstreamBuffer(
     int32 bitstream_buffer_id) {
   // TODO(fischman): this test currently relies on this notification to make
@@ -697,6 +536,7 @@ void GLRenderingVDAClient::NotifyEndOfBitstreamBuffer(
 void GLRenderingVDAClient::NotifyFlushDone() {
   if (decoder_deleted())
     return;
+
   SetState(CS_FLUSHED);
   --remaining_play_throughs_;
   DCHECK_GE(remaining_play_throughs_, 0);
@@ -710,6 +550,8 @@ void GLRenderingVDAClient::NotifyResetDone() {
   if (decoder_deleted())
     return;
 
+  rendering_helper_->DropPendingFrames(window_id_);
+
   if (reset_after_frame_num_ == MID_STREAM_RESET) {
     reset_after_frame_num_ = END_OF_STREAM_RESET;
     DecodeNextFragment();
@@ -723,7 +565,7 @@ void GLRenderingVDAClient::NotifyResetDone() {
 
   if (remaining_play_throughs_) {
     encoded_data_next_pos_to_decode_ = 0;
-    NotifyInitializeDone();
+    FinishInitialization();
     return;
   }
 
@@ -750,10 +592,6 @@ void GLRenderingVDAClient::OutputFrameDeliveryTimes(base::File* output) {
   }
 }
 
-void GLRenderingVDAClient::NotifyFrameDropped(int32 picture_buffer_id) {
-  decoder_->ReusePictureBuffer(picture_buffer_id);
-}
-
 static bool LookingAtNAL(const std::string& encoded, size_t pos) {
   return encoded[pos] == 0 && encoded[pos + 1] == 0 &&
       encoded[pos + 2] == 0 && encoded[pos + 3] == 1;
@@ -768,10 +606,26 @@ void GLRenderingVDAClient::SetState(ClientState new_state) {
   }
 }
 
+void GLRenderingVDAClient::FinishInitialization() {
+  SetState(CS_INITIALIZED);
+  initialize_done_ticks_ = base::TimeTicks::Now();
+
+  if (reset_after_frame_num_ == START_OF_STREAM_RESET) {
+    reset_after_frame_num_ = MID_STREAM_RESET;
+    decoder_->Reset();
+    return;
+  }
+
+  for (int i = 0; i < num_in_flight_decodes_; ++i)
+    DecodeNextFragment();
+  DCHECK_EQ(outstanding_decodes_, num_in_flight_decodes_);
+}
+
 void GLRenderingVDAClient::DeleteDecoder() {
   if (decoder_deleted())
     return;
-  decoder_.release()->Destroy();
+  weak_decoder_factory_.reset();
+  decoder_.reset();
   STLClearObject(&encoded_data_);
   for (std::set<int>::iterator it = outstanding_texture_ids_.begin();
        it != outstanding_texture_ids_.end(); ++it) {
@@ -936,27 +790,20 @@ void GLRenderingVDAClient::DecodeNextFragment() {
   }
 }
 
-int GLRenderingVDAClient::num_decoded_frames() {
-  return throttling_client_ ? throttling_client_->num_decoded_frames()
-                            : num_decoded_frames_;
-}
-
 double GLRenderingVDAClient::frames_per_second() {
   base::TimeDelta delta = frame_delivery_times_.back() - initialize_done_ticks_;
-  if (delta.InSecondsF() == 0)
-    return 0;
-  return num_decoded_frames() / delta.InSecondsF();
+  return num_decoded_frames_ / delta.InSecondsF();
 }
 
-int GLRenderingVDAClient::decode_time_median() {
+base::TimeDelta GLRenderingVDAClient::decode_time_median() {
   if (decode_time_.size() == 0)
-    return 0;
+    return base::TimeDelta();
   std::sort(decode_time_.begin(), decode_time_.end());
   int index = decode_time_.size() / 2;
   if (decode_time_.size() % 2 != 0)
-    return decode_time_[index].InMilliseconds();
+    return decode_time_[index];
 
-  return (decode_time_[index] + decode_time_[index - 1]).InMilliseconds() / 2;
+  return (decode_time_[index] + decode_time_[index - 1]) / 2;
 }
 
 class VideoDecodeAcceleratorTest : public ::testing::Test {
@@ -1199,34 +1046,22 @@ TEST_P(VideoDecodeAcceleratorParamTest, TestSimpleDecode) {
   UpdateTestVideoFileParams(
       num_concurrent_decoders, reset_point, &test_video_files_);
 
-  // Suppress GL rendering for all tests when the "--disable_rendering" is set.
-  const bool suppress_rendering = g_disable_rendering;
+  // Suppress GL rendering for all tests when the "--rendering_fps" is 0.
+  const bool suppress_rendering = g_rendering_fps == 0;
 
   std::vector<ClientStateNotification<ClientState>*>
       notes(num_concurrent_decoders, NULL);
   std::vector<GLRenderingVDAClient*> clients(num_concurrent_decoders, NULL);
 
   RenderingHelperParams helper_params;
-  helper_params.num_windows = num_concurrent_decoders;
+  helper_params.rendering_fps = g_rendering_fps;
   helper_params.render_as_thumbnails = render_as_thumbnails;
   if (render_as_thumbnails) {
     // Only one decoder is supported with thumbnail rendering
     CHECK_EQ(num_concurrent_decoders, 1U);
-    gfx::Size frame_size(test_video_files_[0]->width,
-                         test_video_files_[0]->height);
-    helper_params.frame_dimensions.push_back(frame_size);
-    helper_params.window_dimensions.push_back(kThumbnailsDisplaySize);
     helper_params.thumbnails_page_size = kThumbnailsPageSize;
     helper_params.thumbnail_size = kThumbnailSize;
-  } else {
-    for (size_t index = 0; index < test_video_files_.size(); ++index) {
-      gfx::Size frame_size(test_video_files_[index]->width,
-                           test_video_files_[index]->height);
-      helper_params.frame_dimensions.push_back(frame_size);
-      helper_params.window_dimensions.push_back(frame_size);
-    }
   }
-  InitializeRenderingHelper(helper_params);
 
   // First kick off all the decoders.
   for (size_t index = 0; index < num_concurrent_decoders; ++index) {
@@ -1243,8 +1078,8 @@ TEST_P(VideoDecodeAcceleratorParamTest, TestSimpleDecode) {
     }
 
     GLRenderingVDAClient* client =
-        new GLRenderingVDAClient(&rendering_helper_,
-                                 index,
+        new GLRenderingVDAClient(index,
+                                 &rendering_helper_,
                                  note,
                                  video_file->data_str,
                                  num_in_flight_decodes,
@@ -1254,14 +1089,24 @@ TEST_P(VideoDecodeAcceleratorParamTest, TestSimpleDecode) {
                                  video_file->width,
                                  video_file->height,
                                  video_file->profile,
-                                 g_rendering_fps,
                                  suppress_rendering,
                                  delay_after_frame_num,
-                                 0);
+                                 0,
+                                 render_as_thumbnails);
+
     clients[index] = client;
+    helper_params.window_sizes.push_back(
+        render_as_thumbnails
+            ? kThumbnailsPageSize
+            : gfx::Size(video_file->width, video_file->height));
+  }
 
-    CreateAndStartDecoder(client, note);
+  InitializeRenderingHelper(helper_params);
+
+  for (size_t index = 0; index < num_concurrent_decoders; ++index) {
+    CreateAndStartDecoder(clients[index], notes[index]);
   }
+
   // Then wait for all the decodes to finish.
   // Only check performance & correctness later if we play through only once.
   bool skip_performance_and_correctness_checks = num_play_throughs > 1;
@@ -1324,7 +1169,7 @@ TEST_P(VideoDecodeAcceleratorParamTest, TestSimpleDecode) {
       EXPECT_EQ(client->num_done_bitstream_buffers(),
                 client->num_queued_fragments());
     }
-    VLOG(0) << "Decoder " << i << " fps: " << client->frames_per_second();
+    LOG(INFO) << "Decoder " << i << " fps: " << client->frames_per_second();
     if (!render_as_thumbnails) {
       int min_fps = suppress_rendering ?
           video_file->min_fps_no_render : video_file->min_fps_render;
@@ -1478,19 +1323,16 @@ INSTANTIATE_TEST_CASE_P(
 // second.
 TEST_F(VideoDecodeAcceleratorTest, TestDecodeTimeMedian) {
   RenderingHelperParams helper_params;
-  helper_params.num_windows = 1;
+
+  // Disable rendering by setting the rendering_fps = 0.
+  helper_params.rendering_fps = 0;
   helper_params.render_as_thumbnails = false;
-  gfx::Size frame_size(test_video_files_[0]->width,
-                       test_video_files_[0]->height);
-  helper_params.frame_dimensions.push_back(frame_size);
-  helper_params.window_dimensions.push_back(frame_size);
-  InitializeRenderingHelper(helper_params);
 
   ClientStateNotification<ClientState>* note =
       new ClientStateNotification<ClientState>();
   GLRenderingVDAClient* client =
-      new GLRenderingVDAClient(&rendering_helper_,
-                               0,
+      new GLRenderingVDAClient(0,
+                               &rendering_helper_,
                                note,
                                test_video_files_[0]->data_str,
                                1,
@@ -1500,18 +1342,21 @@ TEST_F(VideoDecodeAcceleratorTest, TestDecodeTimeMedian) {
                                test_video_files_[0]->width,
                                test_video_files_[0]->height,
                                test_video_files_[0]->profile,
-                               g_rendering_fps,
                                true,
                                std::numeric_limits<int>::max(),
-                               kWebRtcDecodeCallsPerSecond);
+                               kWebRtcDecodeCallsPerSecond,
+                               false /* render_as_thumbnail */);
+  helper_params.window_sizes.push_back(
+      gfx::Size(test_video_files_[0]->width, test_video_files_[0]->height));
+  InitializeRenderingHelper(helper_params);
   CreateAndStartDecoder(client, note);
   WaitUntilDecodeFinish(note);
 
-  int decode_time_median = client->decode_time_median();
+  base::TimeDelta decode_time_median = client->decode_time_median();
   std::string output_string =
-      base::StringPrintf("Decode time median: %d ms", decode_time_median);
-  VLOG(0) << output_string;
-  ASSERT_GT(decode_time_median, 0);
+      base::StringPrintf("Decode time median: %" PRId64 " us",
+                         decode_time_median.InMicroseconds());
+  LOG(INFO) << output_string;
 
   if (g_output_log != NULL)
     OutputLogFile(g_output_log, output_string);
@@ -1532,26 +1377,25 @@ TEST_F(VideoDecodeAcceleratorTest, TestDecodeTimeMedian) {
 
 int main(int argc, char **argv) {
   testing::InitGoogleTest(&argc, argv);  // Removes gtest-specific args.
-  CommandLine::Init(argc, argv);
+  base::CommandLine::Init(argc, argv);
 
   // Needed to enable DVLOG through --vmodule.
   logging::LoggingSettings settings;
   settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
   CHECK(logging::InitLogging(settings));
 
-  CommandLine* cmd_line = CommandLine::ForCurrentProcess();
+  const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
   DCHECK(cmd_line);
 
-  CommandLine::SwitchMap switches = cmd_line->GetSwitches();
+  base::CommandLine::SwitchMap switches = cmd_line->GetSwitches();
   for (CommandLine::SwitchMap::const_iterator it = switches.begin();
        it != switches.end(); ++it) {
     if (it->first == "test_video_data") {
       content::g_test_video_data = it->second.c_str();
       continue;
     }
-    // TODO(wuchengli): remove frame_deliver_log after CrOS test get updated.
-    // See http://crosreview.com/175426.
-    if (it->first == "frame_delivery_log" || it->first == "output_log") {
+    // The output log for VDA performance test.
+    if (it->first == "output_log") {
       content::g_output_log = it->second.c_str();
       continue;
     }
@@ -1562,8 +1406,9 @@ int main(int argc, char **argv) {
       CHECK(base::StringToDouble(input, &content::g_rendering_fps));
       continue;
     }
+    // TODO(owenlin): Remove this flag once it is not used in autotest.
     if (it->first == "disable_rendering") {
-      content::g_disable_rendering = true;
+      content::g_rendering_fps = 0;
       continue;
     }
     if (it->first == "v" || it->first == "vmodule")
@@ -1572,6 +1417,7 @@ int main(int argc, char **argv) {
   }
 
   base::ShadowingAtExitManager at_exit_manager;
+  content::RenderingHelper::InitializeOneOff();
 
   return RUN_ALL_TESTS();
 }