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
|
// Copyright (c) 2010 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 "media/base/data_buffer.h"
#include "remoting/base/pixel_format.h"
#include "remoting/host/encoder_vp8.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace remoting {
static const int kWidth = 1024;
static const int kHeight = 768;
static const PixelFormat kPixelFormat = kPixelFormat_YV12;
static void GenerateData(uint8* data, int size) {
for (int i = 0; i < size; ++i) {
data[i] = i;
}
}
class EncodeDoneHandler
: public base::RefCountedThreadSafe<EncodeDoneHandler> {
public:
MOCK_METHOD0(EncodeDone, void());
};
TEST(EncoderVp8Test, SimpleEncode) {
EncoderVp8 encoder;
encoder.SetSize(kWidth, kHeight);
encoder.SetPixelFormat(kPixelFormat);
DirtyRects rects;
rects.push_back(gfx::Rect(kWidth, kHeight));
// Prepare memory for encoding.
int strides[3];
strides[0] = kWidth;
strides[1] = strides[2] = kWidth / 2;
uint8* planes[3];
planes[0] = new uint8[kWidth * kHeight];
planes[1] = new uint8[kWidth * kHeight / 4];
planes[2] = new uint8[kWidth * kHeight / 4];
GenerateData(planes[0], kWidth * kHeight);
GenerateData(planes[1], kWidth * kHeight / 4);
GenerateData(planes[2], kWidth * kHeight / 4);
scoped_refptr<EncodeDoneHandler> handler = new EncodeDoneHandler();
UpdateStreamPacketHeader* header = new UpdateStreamPacketHeader();
scoped_refptr<media::DataBuffer> encoded_data;
bool encode_done = false;
EXPECT_CALL(*handler, EncodeDone());
encoder.Encode(rects, const_cast<const uint8**>(planes),
strides, true, header, &encoded_data, &encode_done,
NewRunnableMethod(handler.get(),
&EncodeDoneHandler::EncodeDone));
EXPECT_TRUE(encode_done);
ASSERT_TRUE(encoded_data.get());
EXPECT_NE(0u, encoded_data->GetBufferSize());
delete [] planes[0];
delete [] planes[1];
delete [] planes[2];
}
} // namespace remoting
|