summaryrefslogtreecommitdiffstats
path: root/media/base
diff options
context:
space:
mode:
Diffstat (limited to 'media/base')
-rw-r--r--media/base/pts_heap.cc21
-rw-r--r--media/base/pts_heap.h69
-rw-r--r--media/base/pts_heap_unittest.cc39
-rw-r--r--media/base/pts_stream.cc79
-rw-r--r--media/base/pts_stream.h70
-rw-r--r--media/base/pts_stream_unittest.cc101
6 files changed, 0 insertions, 379 deletions
diff --git a/media/base/pts_heap.cc b/media/base/pts_heap.cc
deleted file mode 100644
index 84ff5d9..0000000
--- a/media/base/pts_heap.cc
+++ /dev/null
@@ -1,21 +0,0 @@
-// 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/pts_heap.h"
-
-namespace media {
-
-PtsHeap::PtsHeap() {}
-
-PtsHeap::~PtsHeap() {}
-
-void PtsHeap::Push(const base::TimeDelta& pts) {
- queue_.push(pts);
-}
-
-void PtsHeap::Pop() {
- queue_.pop();
-}
-
-} // namespace media
diff --git a/media/base/pts_heap.h b/media/base/pts_heap.h
deleted file mode 100644
index 5e7f3be..0000000
--- a/media/base/pts_heap.h
+++ /dev/null
@@ -1,69 +0,0 @@
-// 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.
-
-#ifndef MEDIA_BASE_PTS_HEAP_H_
-#define MEDIA_BASE_PTS_HEAP_H_
-
-// The compressed frame are often in decode timestamp (dts) order, which
-// may not always be in presentation timestamp (pts) order. However, the
-// decoded frames will always be returned in pts order. Ideally, the pts could
-// be attached as metadata to each comprsesed frame, and the decoder would
-// pass it along in the uncompressed frame so that it can be used in render.
-// Some decoders, like FFmpeg, do not have this facility, so we use PtsHeap to
-// pass along this information and simulate the reodering.
-//
-// Here is an illustration of why the reordering might be necessary.
-//
-// Decode PTS of PTS of
-// Call # Buffer In Buffer Out
-// 1 1 1
-// 2 3 --- <--- frame 3 buffered by Decoder
-// 3 2 2
-// 4 4 3 <--- copying timestamp 4 and 6 would be
-// 5 6 4 <-' incorrect, which is why we sort and
-// 6 5 5 queue incoming timestamps
-//
-// The PtsHeap expects that for every Pop(), there was a corresponding Push().
-// It will CHECK fail otherwise.
-
-#include <queue>
-#include <vector>
-
-#include "base/time.h"
-#include "media/base/media_export.h"
-
-namespace media {
-
-class MEDIA_EXPORT PtsHeap {
- public:
- PtsHeap();
- ~PtsHeap();
-
- void Push(const base::TimeDelta& pts);
- void Pop();
-
- const base::TimeDelta& Top() const { return queue_.top(); }
- bool IsEmpty() const { return queue_.empty(); }
-
- private:
- struct PtsHeapOrdering {
- bool operator()(const base::TimeDelta& lhs,
- const base::TimeDelta& rhs) const {
- // std::priority_queue is a max-heap. We want lower timestamps to show up
- // first so reverse the natural less-than comparison.
- return rhs < lhs;
- }
- };
- typedef std::priority_queue<base::TimeDelta,
- std::vector<base::TimeDelta>,
- PtsHeapOrdering> TimeQueue;
-
- TimeQueue queue_;
-
- DISALLOW_COPY_AND_ASSIGN(PtsHeap);
-};
-
-} // namespace media
-
-#endif // MEDIA_BASE_PTS_HEAP_H_
diff --git a/media/base/pts_heap_unittest.cc b/media/base/pts_heap_unittest.cc
deleted file mode 100644
index 9bc919c..0000000
--- a/media/base/pts_heap_unittest.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-// 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.
-
-#include "base/time.h"
-#include "media/base/pts_heap.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace media {
-
-TEST(PtsHeapTest, IsEmpty) {
- const base::TimeDelta kTestPts1 = base::TimeDelta::FromMicroseconds(123);
-
- PtsHeap heap;
- ASSERT_TRUE(heap.IsEmpty());
- heap.Push(kTestPts1);
- ASSERT_FALSE(heap.IsEmpty());
- heap.Pop();
- ASSERT_TRUE(heap.IsEmpty());
-}
-
-TEST(PtsHeapTest, Ordering) {
- const base::TimeDelta kTestPts1 = base::TimeDelta::FromMicroseconds(123);
- const base::TimeDelta kTestPts2 = base::TimeDelta::FromMicroseconds(456);
-
- PtsHeap heap;
- heap.Push(kTestPts1);
- heap.Push(kTestPts2);
- heap.Push(kTestPts1);
-
- EXPECT_TRUE(kTestPts1 == heap.Top());
- heap.Pop();
- EXPECT_TRUE(kTestPts1 == heap.Top());
- heap.Pop();
- EXPECT_TRUE(kTestPts2 == heap.Top());
- heap.Pop();
-}
-
-} // namespace media
diff --git a/media/base/pts_stream.cc b/media/base/pts_stream.cc
deleted file mode 100644
index 48cec61..0000000
--- a/media/base/pts_stream.cc
+++ /dev/null
@@ -1,79 +0,0 @@
-// 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 "base/logging.h"
-#include "media/base/buffers.h"
-#include "media/base/pts_stream.h"
-
-namespace media {
-
-PtsStream::PtsStream() {}
-
-PtsStream::~PtsStream() {}
-
-void PtsStream::Initialize(const base::TimeDelta& frame_duration) {
- default_duration_ = frame_duration;
- current_pts_ = base::TimeDelta();
- current_duration_ = base::TimeDelta();
-}
-
-void PtsStream::Seek(const base::TimeDelta& timestamp) {
- current_pts_ = timestamp;
- current_duration_ = base::TimeDelta();
- Flush();
-}
-
-void PtsStream::Flush() {
- while (!pts_heap_.IsEmpty())
- pts_heap_.Pop();
-}
-
-void PtsStream::EnqueuePts(StreamSample* sample) {
- DCHECK(sample);
- if (!sample->IsEndOfStream() && sample->GetTimestamp() != kNoTimestamp()) {
- pts_heap_.Push(sample->GetTimestamp());
- }
-}
-
-void PtsStream::UpdatePtsAndDuration(StreamSample* sample) {
- // First search the |sample| for the pts. This is the most authoritative.
- // Make a special exclusion for the value pts == 0. Though this is
- // technically a valid value, it seems a number of FFmpeg codecs will
- // mistakenly always set pts to 0.
- //
- // TODO(scherkus): FFmpegVideoDecodeEngine should be able to detect this
- // situation and set the timestamp to kInvalidTimestamp.
- DCHECK(sample);
- base::TimeDelta timestamp = sample->GetTimestamp();
- if (timestamp != kNoTimestamp() &&
- timestamp.ToInternalValue() != 0) {
- current_pts_ = timestamp;
- // We need to clean up the timestamp we pushed onto the |pts_heap_|.
- if (!pts_heap_.IsEmpty())
- pts_heap_.Pop();
- } else if (!pts_heap_.IsEmpty()) {
- // If the frame did not have pts, try to get the pts from the |pts_heap|.
- current_pts_ = pts_heap_.Top();
- pts_heap_.Pop();
- } else if (current_pts_ != kNoTimestamp()) {
- // Guess assuming this frame was the same as the last frame.
- current_pts_ = current_pts_ + current_duration_;
- } else {
- // Now we really have no clue!!! Mark an invalid timestamp and let the
- // video renderer handle it (i.e., drop frame).
- current_pts_ = kNoTimestamp();
- }
-
- // Fill in the duration, using the frame itself as the authoratative source.
- base::TimeDelta duration = sample->GetDuration();
- if (duration != kNoTimestamp() &&
- duration.ToInternalValue() != 0) {
- current_duration_ = duration;
- } else {
- // Otherwise assume a normal frame duration.
- current_duration_ = default_duration_;
- }
-}
-
-} // namespace media
diff --git a/media/base/pts_stream.h b/media/base/pts_stream.h
deleted file mode 100644
index 095ae7f..0000000
--- a/media/base/pts_stream.h
+++ /dev/null
@@ -1,70 +0,0 @@
-// 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.
-
-#ifndef MEDIA_BASE_PTS_STREAM_H_
-#define MEDIA_BASE_PTS_STREAM_H_
-
-// Under some conditions the decoded frames can get invalid or wrong timestamps:
-// - compressed frames are often in decode timestamp (dts) order, which
-// may not always be in presentation timestamp (pts) order;
-// - decoder may report invalid timestamps for the decoded frames;
-// - parser may report invalid timestamps for the compressed frames.
-//
-// To ensure that the decoded frames are displayed in the proper order, the
-// PtsStream class assembles the time information from different sources and
-// combines it into the "best guess" timestamp and duration for the current
-// frame. Data inside the decoded frame (if provided) is trusted the most,
-// followed by data from the packet stream. Estimation based on the last known
-// PTS and frame rate is reserved as a last-ditch effort.
-
-#include "base/time.h"
-#include "media/base/pts_heap.h"
-
-namespace media {
-
-class StreamSample;
-
-class MEDIA_EXPORT PtsStream {
- public:
- PtsStream();
- ~PtsStream();
-
- // Initializes an instance using |frame_duration| as default. In absence of
- // other PTS information PtsStream will produce timestamps separated in time
- // by this duration.
- void Initialize(const base::TimeDelta& frame_duration);
-
- // Sets the |current_pts_| to specified |timestamp| and flushes all enqueued
- // timestamps.
- void Seek(const base::TimeDelta& timestamp);
-
- // Clears the PTS queue.
- void Flush();
-
- // Puts timestamp from the stream packet |sample| into a queue, which is used
- // as PTS source if decoded frames don't have a valid timestamp. Only valid
- // timestamps are enqueued.
- void EnqueuePts(StreamSample* sample);
-
- // Combines data from the decoded |sample|, PTS queue, and PTS estimator
- // into the final PTS and duration.
- void UpdatePtsAndDuration(StreamSample* sample);
-
- base::TimeDelta current_pts() const { return current_pts_; }
- base::TimeDelta current_duration() const { return current_duration_; }
-
- private:
- base::TimeDelta default_duration_; // Frame duration based on the frame rate.
-
- PtsHeap pts_heap_; // Heap of presentation timestamps.
-
- base::TimeDelta current_pts_;
- base::TimeDelta current_duration_;
-
- DISALLOW_COPY_AND_ASSIGN(PtsStream);
-};
-
-} // namespace media
-
-#endif // MEDIA_BASE_PTS_STREAM_H_
diff --git a/media/base/pts_stream_unittest.cc b/media/base/pts_stream_unittest.cc
deleted file mode 100644
index 5b200b7..0000000
--- a/media/base/pts_stream_unittest.cc
+++ /dev/null
@@ -1,101 +0,0 @@
-// 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