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
92
93
94
95
96
97
98
99
100
101
|
// Copyright (c) 2012 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/pts_stream.h"
#include "media/base/video_frame.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
class PtsStreamTest : public testing::Test {
public:
PtsStreamTest() {
video_frame_ = VideoFrame::CreateBlackFrame(16, 16);
// Use typical frame rate of 25 fps.
base::TimeDelta frame_duration = base::TimeDelta::FromMicroseconds(40000);
pts_stream_.Initialize(frame_duration);
}
virtual ~PtsStreamTest() {}
protected:
PtsStream pts_stream_;
scoped_refptr<VideoFrame> video_frame_;
private:
DISALLOW_COPY_AND_ASSIGN(PtsStreamTest);
};
TEST_F(PtsStreamTest, NoTimestamp) {
// Simulate an uninitialized |video_frame| where we cannot determine a
// timestamp at all.
video_frame_->SetTimestamp(kNoTimestamp());
video_frame_->SetDuration(kNoTimestamp());
pts_stream_.UpdatePtsAndDuration(video_frame_);
EXPECT_EQ(0, pts_stream_.current_pts().InMicroseconds());
EXPECT_EQ(40000, pts_stream_.current_duration().InMicroseconds());
}
TEST_F(PtsStreamTest, LastKnownTimestamp) {
// Setup the last known pts to be at 100 microseconds with 16 microsecond
// duration.
video_frame_->SetTimestamp(base::TimeDelta::FromMicroseconds(100));
video_frame_->SetDuration(base::TimeDelta::FromMicroseconds(16));
pts_stream_.UpdatePtsAndDuration(video_frame_);
// Simulate an uninitialized |video_frame| where last known pts will be used
// to generate a timestamp and |frame_duration| will be used to generate a
// duration.
video_frame_->SetTimestamp(kNoTimestamp());
video_frame_->SetDuration(kNoTimestamp());
pts_stream_.UpdatePtsAndDuration(video_frame_);
EXPECT_EQ(116, pts_stream_.current_pts().InMicroseconds());
EXPECT_EQ(40000, pts_stream_.current_duration().InMicroseconds());
}
TEST_F(PtsStreamTest, TimestampIsZero) {
// Test that having pts == 0 in the frame also behaves like the pts is not
// provided. This is because FFmpeg set the pts to zero when there is no
// data for the frame, which means that value is useless to us.
//
// TODO(scherkus): FFmpegVideoDecodeEngine should be able to detect this
// situation and set the timestamp to kInvalidTimestamp.
video_frame_->SetTimestamp(base::TimeDelta::FromMicroseconds(100));
video_frame_->SetDuration(base::TimeDelta::FromMicroseconds(16));
pts_stream_.UpdatePtsAndDuration(video_frame_);
EXPECT_EQ(100, pts_stream_.current_pts().InMicroseconds());
EXPECT_EQ(16, pts_stream_.current_duration().InMicroseconds());
// Should use estimation and default frame rate.
video_frame_->SetTimestamp(base::TimeDelta::FromMicroseconds(0));
video_frame_->SetDuration(base::TimeDelta::FromMicroseconds(0));
pts_stream_.UpdatePtsAndDuration(video_frame_);
EXPECT_EQ(116, pts_stream_.current_pts().InMicroseconds());
EXPECT_EQ(40000, pts_stream_.current_duration().InMicroseconds());
// Should override estimation but still use default frame rate.
video_frame_->SetTimestamp(base::TimeDelta::FromMicroseconds(200));
video_frame_->SetDuration(base::TimeDelta::FromMicroseconds(0));
pts_stream_.EnqueuePts(video_frame_);
video_frame_->SetTimestamp(base::TimeDelta::FromMicroseconds(0));
video_frame_->SetDuration(base::TimeDelta::FromMicroseconds(0));
pts_stream_.UpdatePtsAndDuration(video_frame_);
EXPECT_EQ(200, pts_stream_.current_pts().InMicroseconds());
EXPECT_EQ(40000, pts_stream_.current_duration().InMicroseconds());
// Should override estimation and frame rate.
video_frame_->SetTimestamp(base::TimeDelta::FromMicroseconds(456));
video_frame_->SetDuration(base::TimeDelta::FromMicroseconds(0));
pts_stream_.EnqueuePts(video_frame_);
video_frame_->SetTimestamp(base::TimeDelta::FromMicroseconds(0));
video_frame_->SetDuration(base::TimeDelta::FromMicroseconds(789));
pts_stream_.UpdatePtsAndDuration(video_frame_);
EXPECT_EQ(456, pts_stream_.current_pts().InMicroseconds());
EXPECT_EQ(789, pts_stream_.current_duration().InMicroseconds());
}
} // namespace media
|