summaryrefslogtreecommitdiffstats
path: root/content/renderer/gpu_video_service_host.cc
blob: eeedb9aa5da562ea7bfea06c889d724f79b2db3e (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2011 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 "content/renderer/gpu_video_service_host.h"

#include "content/common/gpu/gpu_messages.h"
#include "content/renderer/gpu_video_decode_accelerator_host.h"
#include "content/renderer/render_thread.h"
#include "media/video/video_decode_accelerator.h"

GpuVideoServiceHost::GpuVideoServiceHost()
    : channel_(NULL),
      next_decoder_host_id_(0) {
}

GpuVideoServiceHost::~GpuVideoServiceHost() {
}

void GpuVideoServiceHost::OnFilterAdded(IPC::Channel* channel) {
  base::Closure on_initialized;
  {
    base::AutoLock auto_lock(lock_);
    DCHECK(!channel_);
    channel_ = channel;
    on_initialized = on_initialized_;
  }
  if (!on_initialized.is_null())
    on_initialized.Run();
}

void GpuVideoServiceHost::OnFilterRemoved() {
  // TODO(hclam): Implement.
}

void GpuVideoServiceHost::OnChannelClosing() {
  // TODO(hclam): Implement.
}

bool GpuVideoServiceHost::OnMessageReceived(const IPC::Message& msg) {
  switch (msg.type()) {
    case AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed::ID:
    case AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers::ID:
    case AcceleratedVideoDecoderHostMsg_CreateDone::ID:
    case AcceleratedVideoDecoderHostMsg_InitializeDone::ID:
    case AcceleratedVideoDecoderHostMsg_DismissPictureBuffer::ID:
    case AcceleratedVideoDecoderHostMsg_PictureReady::ID:
    case AcceleratedVideoDecoderHostMsg_FlushDone::ID:
    case AcceleratedVideoDecoderHostMsg_AbortDone::ID:
    case AcceleratedVideoDecoderHostMsg_EndOfStream::ID:
    case AcceleratedVideoDecoderHostMsg_ErrorNotification::ID:
      if (router_.RouteMessage(msg))
        return true;
      LOG(ERROR) << "AcceleratedVideoDecoderHostMsg cannot be dispatched.";
    default:
      return false;
  }
}

void GpuVideoServiceHost::SetOnInitialized(
    const base::Closure& on_initialized) {
  IPC::Channel* channel;
  {
    base::AutoLock auto_lock(lock_);
    DCHECK(on_initialized_.is_null());
    on_initialized_ = on_initialized;
    channel = channel_;
  }
  if (channel)
    on_initialized.Run();
}

GpuVideoDecoderHost* GpuVideoServiceHost::CreateVideoDecoder(
    int context_route_id) {
  // TODO(vrk): Delete all references to GpuVideoDecoder (deprecated).
  return NULL;
}

GpuVideoDecodeAcceleratorHost* GpuVideoServiceHost::CreateVideoAccelerator(
    media::VideoDecodeAccelerator::Client* client) {
  base::AutoLock auto_lock(lock_);
  DCHECK(channel_);
  return new GpuVideoDecodeAcceleratorHost(
      &router_, channel_, next_decoder_host_id_++, client);
}