blob: 9a39933f983cd031b1daeba6f37df651a595b3cb (
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
86
87
88
89
90
91
|
// Copyright (c) 2009 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.
//
// The video renderer implementation to be use by the media pipeline. It lives
// inside video renderer thread and also WebKit's main thread. We need to be
// extra careful about members shared by two different threads, especially
// video frame buffers.
//
// Methods called from WebKit's main thread:
// Paint()
// SetRect()
#ifndef CHROME_RENDERER_MEDIA_VIDEO_RENDERER_IMPL_H_
#define CHROME_RENDERER_MEDIA_VIDEO_RENDERER_IMPL_H_
#include "base/gfx/platform_canvas.h"
#include "base/gfx/rect.h"
#include "base/gfx/size.h"
#include "chrome/renderer/webmediaplayer_impl.h"
#include "media/base/buffers.h"
#include "media/base/factory.h"
#include "media/base/filters.h"
#include "media/filters/video_renderer_base.h"
#include "third_party/WebKit/WebKit/chromium/public/WebMediaPlayer.h"
class VideoRendererImpl : public media::VideoRendererBase {
public:
// Methods for painting called by the WebMediaPlayerDelegateImpl
// This method is called with the same rect as the Paint method and could
// be used by future implementations to implement an improved color space +
// scale code on a seperate thread. Since we always do the streach on the
// same thread as the Paint method, we just ignore the call for now.
virtual void SetRect(const gfx::Rect& rect) {}
// Paint the current front frame on the |canvas| streaching it to fit the
// |dest_rect|
virtual void Paint(skia::PlatformCanvas* canvas, const gfx::Rect& dest_rect);
// Static method for creating factory for this object.
static media::FilterFactory* CreateFactory(WebMediaPlayerImpl* delegate) {
return new media::FilterFactoryImpl1<VideoRendererImpl,
WebMediaPlayerImpl*>(delegate);
}
private:
// Method called by base class during initialization.
virtual bool OnInitialize(size_t width, size_t height);
// Method called by VideoRendererBase to tell us to stop.
virtual void OnStop();
// Method called by the VideoRendererBase when a repaint is needed.
virtual void OnPaintNeeded();
friend class media::FilterFactoryImpl1<VideoRendererImpl,
WebMediaPlayerImpl*>;
// Constructor and destructor are private. Only the filter factory is
// allowed to create instances.
explicit VideoRendererImpl(WebMediaPlayerImpl* delegate);
virtual ~VideoRendererImpl() {}
// Internal method used by the Paint method to convert the specified video
// frame to RGB, placing the converted pixels in the |current_frame_| bitmap.
void CopyToCurrentFrame(media::VideoFrame* video_frame);
// Pointer to our parent object that is called to request repaints.
WebMediaPlayerImpl* delegate_;
// An RGB bitmap used to convert the video frames.
SkBitmap bitmap_;
// These two members are used to determine if the |bitmap_| contains
// an already converted image of the current frame. IMPORTANT NOTE: The
// value of |last_converted_frame_| must only be used for comparison purposes,
// and it should be assumed that the value of the pointer is INVALID unless
// it matches the pointer returned from GetCurrentFrame(). Even then, just
// to make sure, we compare the timestamp to be sure the bits in the
// |current_frame_bitmap_| are valid.
media::VideoFrame* last_converted_frame_;
base::TimeDelta last_converted_timestamp_;
// The size of the video.
gfx::Size video_size_;
DISALLOW_COPY_AND_ASSIGN(VideoRendererImpl);
};
#endif // CHROME_RENDERER_MEDIA_VIDEO_RENDERER_IMPL_H_
|