mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 1355740 - Change the type of TrackInfo::mDuration to TimeUnit. r=jya
MozReview-Commit-ID: P7aqw4d5Vk --HG-- extra : rebase_source : f22743fec9c8b70cbb092e3b26e252e7a4cb0b31 extra : source : 2413cd58f073b734a2cb85cec3658942bfd46e08
This commit is contained in:
parent
960040daf9
commit
f45fa7374e
@ -405,7 +405,7 @@ ADTSTrackDemuxer::Init()
|
||||
mInfo->mRate = mSamplesPerSecond;
|
||||
mInfo->mChannels = mChannels;
|
||||
mInfo->mBitDepth = 16;
|
||||
mInfo->mDuration = Duration().ToMicroseconds();
|
||||
mInfo->mDuration = Duration();
|
||||
|
||||
// AAC Specific information
|
||||
mInfo->mMimeType = "audio/mp4a-latm";
|
||||
@ -424,7 +424,8 @@ ADTSTrackDemuxer::Init()
|
||||
|
||||
ADTSLOG("Init mInfo={mRate=%u mChannels=%u mBitDepth=%u mDuration=%" PRId64
|
||||
"}",
|
||||
mInfo->mRate, mInfo->mChannels, mInfo->mBitDepth, mInfo->mDuration);
|
||||
mInfo->mRate, mInfo->mChannels, mInfo->mBitDepth,
|
||||
mInfo->mDuration.ToMicroseconds());
|
||||
|
||||
return mSamplesPerSecond && mChannels;
|
||||
}
|
||||
|
@ -144,11 +144,11 @@ MP3TrackDemuxer::Init()
|
||||
mInfo->mChannels = mChannels;
|
||||
mInfo->mBitDepth = 16;
|
||||
mInfo->mMimeType = "audio/mpeg";
|
||||
mInfo->mDuration = Duration().ToMicroseconds();
|
||||
mInfo->mDuration = Duration();
|
||||
|
||||
MP3LOG("Init mInfo={mRate=%d mChannels=%d mBitDepth=%d mDuration=%" PRId64 "}",
|
||||
mInfo->mRate, mInfo->mChannels, mInfo->mBitDepth,
|
||||
mInfo->mDuration);
|
||||
mInfo->mDuration.ToMicroseconds());
|
||||
|
||||
return mSamplesPerSecond && mChannels;
|
||||
}
|
||||
|
@ -1420,12 +1420,12 @@ MediaFormatReader::OnDemuxerInitDone(const MediaResult& aResult)
|
||||
mInfo.mCrypto = *crypto;
|
||||
}
|
||||
|
||||
int64_t videoDuration = HasVideo() ? mInfo.mVideo.mDuration : 0;
|
||||
int64_t audioDuration = HasAudio() ? mInfo.mAudio.mDuration : 0;
|
||||
auto videoDuration = HasVideo() ? mInfo.mVideo.mDuration : TimeUnit::Zero();
|
||||
auto audioDuration = HasAudio() ? mInfo.mAudio.mDuration : TimeUnit::Zero();
|
||||
|
||||
int64_t duration = std::max(videoDuration, audioDuration);
|
||||
if (duration != -1) {
|
||||
mInfo.mMetadataDuration = Some(TimeUnit::FromMicroseconds(duration));
|
||||
auto duration = std::max(videoDuration, audioDuration);
|
||||
if (duration.IsPositive()) {
|
||||
mInfo.mMetadataDuration = Some(duration);
|
||||
}
|
||||
|
||||
mInfo.mMediaSeekable = mDemuxer->IsSeekable();
|
||||
|
@ -62,7 +62,6 @@ public:
|
||||
, mLanguage(aLanguage)
|
||||
, mEnabled(aEnabled)
|
||||
, mTrackId(aTrackId)
|
||||
, mDuration(0)
|
||||
, mMediaTime(0)
|
||||
, mIsRenderedExternally(false)
|
||||
, mType(aType)
|
||||
@ -94,7 +93,7 @@ public:
|
||||
TrackID mTrackId;
|
||||
|
||||
nsCString mMimeType;
|
||||
int64_t mDuration;
|
||||
media::TimeUnit mDuration;
|
||||
int64_t mMediaTime;
|
||||
CryptoTrack mCrypto;
|
||||
|
||||
|
@ -161,6 +161,10 @@ public:
|
||||
return mValue.value() == INT64_MAX;
|
||||
}
|
||||
|
||||
bool IsPositive() const {
|
||||
return mValue.value() > 0;
|
||||
}
|
||||
|
||||
bool operator == (const TimeUnit& aOther) const {
|
||||
MOZ_ASSERT(IsValid() && aOther.IsValid());
|
||||
return mValue.value() == aOther.mValue.value();
|
||||
|
@ -681,7 +681,7 @@ FlacTrackDemuxer::Init()
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!mParser->Info().IsValid() || !mParser->Info().mDuration) {
|
||||
if (!mParser->Info().IsValid() || !mParser->Info().mDuration.IsPositive()) {
|
||||
// Check if we can look at the last frame for the end time to determine the
|
||||
// duration when we don't have any.
|
||||
TimeAtEnd();
|
||||
@ -706,7 +706,7 @@ FlacTrackDemuxer::GetInfo() const
|
||||
} else if (mParser->FirstFrame().Info().IsValid()) {
|
||||
// Use the first frame header.
|
||||
UniquePtr<TrackInfo> info = mParser->FirstFrame().Info().Clone();
|
||||
info->mDuration = Duration().ToMicroseconds();
|
||||
info->mDuration = Duration();
|
||||
return info;
|
||||
}
|
||||
return nullptr;
|
||||
@ -717,7 +717,7 @@ FlacTrackDemuxer::IsSeekable() const
|
||||
{
|
||||
// For now we only allow seeking if a STREAMINFO block was found and with
|
||||
// a known number of samples (duration is set).
|
||||
return mParser->Info().IsValid() && mParser->Info().mDuration;
|
||||
return mParser->Info().IsValid() && mParser->Info().mDuration.IsPositive();
|
||||
}
|
||||
|
||||
RefPtr<FlacTrackDemuxer::SeekPromise>
|
||||
@ -1015,8 +1015,7 @@ FlacTrackDemuxer::AverageFrameLength() const
|
||||
TimeUnit
|
||||
FlacTrackDemuxer::Duration() const
|
||||
{
|
||||
return std::max(mParsedFramesDuration,
|
||||
TimeUnit::FromMicroseconds(mParser->Info().mDuration));
|
||||
return std::max(mParsedFramesDuration, mParser->Info().mDuration);
|
||||
}
|
||||
|
||||
TimeUnit
|
||||
|
@ -148,9 +148,8 @@ FlacFrameParser::DecodeHeaderBlock(const uint8_t* aPacket, size_t aLength)
|
||||
mInfo.mChannels = numChannels;
|
||||
mInfo.mBitDepth = bps;
|
||||
mInfo.mCodecSpecificConfig->AppendElements(blockDataStart, blockDataSize);
|
||||
CheckedInt64 duration =
|
||||
SaferMultDiv(mNumFrames, USECS_PER_S, sampleRate);
|
||||
mInfo.mDuration = duration.isValid() ? duration.value() : 0;
|
||||
auto duration = FramesToTimeUnit(mNumFrames, sampleRate);
|
||||
mInfo.mDuration = duration.IsValid() ? duration : media::TimeUnit::Zero();
|
||||
mParser = new OpusParser;
|
||||
break;
|
||||
}
|
||||
|
@ -220,7 +220,7 @@ CreateTestH264Decoder(layers::KnowsCompositor* aKnowsCompositor,
|
||||
{
|
||||
aConfig.mMimeType = "video/avc";
|
||||
aConfig.mId = 1;
|
||||
aConfig.mDuration = 40000;
|
||||
aConfig.mDuration = media::TimeUnit::FromMicroseconds(40000);
|
||||
aConfig.mMediaTime = 0;
|
||||
aConfig.mImage = aConfig.mDisplay = nsIntSize(640, 360);
|
||||
aConfig.mExtraData = new MediaByteBuffer();
|
||||
|
@ -990,8 +990,8 @@ TrackBuffersManager::OnDemuxerInitDone(const MediaResult& aResult)
|
||||
info.mAudio.mTrackId = 1;
|
||||
}
|
||||
|
||||
int64_t videoDuration = numVideos ? info.mVideo.mDuration : 0;
|
||||
int64_t audioDuration = numAudios ? info.mAudio.mDuration : 0;
|
||||
int64_t videoDuration = numVideos ? info.mVideo.mDuration.ToMicroseconds() : 0;
|
||||
int64_t audioDuration = numAudios ? info.mAudio.mDuration.ToMicroseconds() : 0;
|
||||
|
||||
int64_t duration = std::max(videoDuration, audioDuration);
|
||||
// 1. Update the duration attribute if it currently equals NaN.
|
||||
|
@ -581,10 +581,10 @@ OggDemuxer::ReadMetadata()
|
||||
mInfo.mMetadataDuration.emplace(TimeUnit::FromInfinity());
|
||||
}
|
||||
if (HasAudio()) {
|
||||
mInfo.mAudio.mDuration = mInfo.mMetadataDuration->ToMicroseconds();
|
||||
mInfo.mAudio.mDuration = mInfo.mMetadataDuration.ref();
|
||||
}
|
||||
if (HasVideo()) {
|
||||
mInfo.mVideo.mDuration = mInfo.mMetadataDuration->ToMicroseconds();
|
||||
mInfo.mVideo.mDuration = mInfo.mMetadataDuration.ref();
|
||||
}
|
||||
} else {
|
||||
OGG_DEBUG("no audio or video tracks");
|
||||
|
@ -515,7 +515,7 @@ D3D9DXVA2Manager::CreateDXVA2Decoder(const VideoInfo& aVideoInfo,
|
||||
desc.Format = (D3DFORMAT)MAKEFOURCC('N','V','1','2');
|
||||
|
||||
// Assume the current duration is representative for the entire video.
|
||||
float framerate = 1000000.0 / aVideoInfo.mDuration;
|
||||
float framerate = 1000000.0 / aVideoInfo.mDuration.ToMicroseconds();
|
||||
if (IsUnsupportedResolution(desc.SampleWidth, desc.SampleHeight, framerate)) {
|
||||
return false;
|
||||
}
|
||||
@ -1102,7 +1102,7 @@ D3D11DXVA2Manager::CreateDXVA2Decoder(const VideoInfo& aVideoInfo,
|
||||
desc.SampleHeight = aVideoInfo.mImage.height;
|
||||
|
||||
// Assume the current duration is representative for the entire video.
|
||||
float framerate = 1000000.0 / aVideoInfo.mDuration;
|
||||
float framerate = 1000000.0 / aVideoInfo.mDuration.ToMicroseconds();
|
||||
if (IsUnsupportedResolution(desc.SampleWidth, desc.SampleHeight, framerate)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -161,9 +161,9 @@ WAVTrackDemuxer::Init()
|
||||
mInfo->mExtendedProfile = (mFmtParser.FmtChunk().WaveFormat() & 0xFF00) >> 8;
|
||||
mInfo->mMimeType = "audio/wave; codecs=";
|
||||
mInfo->mMimeType.AppendInt(mFmtParser.FmtChunk().WaveFormat());
|
||||
mInfo->mDuration = Duration().ToMicroseconds();
|
||||
mInfo->mDuration = Duration();
|
||||
|
||||
return !!(mInfo->mDuration);
|
||||
return mInfo->mDuration.IsPositive();
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -390,8 +390,7 @@ WebMDemuxer::ReadMetadata()
|
||||
uint64_t duration = 0;
|
||||
r = nestegg_duration(context, &duration);
|
||||
if (!r) {
|
||||
mInfo.mVideo.mDuration =
|
||||
media::TimeUnit::FromNanoseconds(duration).ToMicroseconds();
|
||||
mInfo.mVideo.mDuration = media::TimeUnit::FromNanoseconds(duration);
|
||||
}
|
||||
mInfo.mVideo.mCrypto = GetTrackCrypto(TrackInfo::kVideoTrack, track);
|
||||
if (mInfo.mVideo.mCrypto.mValid) {
|
||||
@ -458,8 +457,7 @@ WebMDemuxer::ReadMetadata()
|
||||
uint64_t duration = 0;
|
||||
r = nestegg_duration(context, &duration);
|
||||
if (!r) {
|
||||
mInfo.mAudio.mDuration =
|
||||
media::TimeUnit::FromNanoseconds(duration).ToMicroseconds();
|
||||
mInfo.mAudio.mDuration = media::TimeUnit::FromNanoseconds(duration);
|
||||
}
|
||||
mInfo.mAudio.mCrypto = GetTrackCrypto(TrackInfo::kAudioTrack, track);
|
||||
if (mInfo.mAudio.mCrypto.mValid) {
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "mp4parse.h"
|
||||
|
||||
using namespace stagefright;
|
||||
using mozilla::media::TimeUnit;
|
||||
|
||||
namespace mp4_demuxer
|
||||
{
|
||||
@ -114,7 +115,8 @@ UpdateTrackInfo(mozilla::TrackInfo& aConfig,
|
||||
{
|
||||
mozilla::CryptoTrack& crypto = aConfig.mCrypto;
|
||||
aConfig.mMimeType = aMimeType;
|
||||
aConfig.mDuration = FindInt64(aMetaData, kKeyDuration);
|
||||
aConfig.mDuration = TimeUnit::FromMicroseconds(
|
||||
FindInt64(aMetaData, kKeyDuration));
|
||||
aConfig.mMediaTime = FindInt64(aMetaData, kKeyMediaTime);
|
||||
aConfig.mTrackId = FindInt32(aMetaData, kKeyTrackID);
|
||||
aConfig.mCrypto.mValid = aMetaData->findInt32(kKeyCryptoMode, &crypto.mMode) &&
|
||||
@ -228,7 +230,7 @@ MP4AudioInfo::Update(const mp4parse_track_info* track,
|
||||
mChannels = audio->channels;
|
||||
mBitDepth = audio->bit_depth;
|
||||
mExtendedProfile = audio->profile;
|
||||
mDuration = track->duration;
|
||||
mDuration = TimeUnit::FromMicroseconds(track->duration);
|
||||
mMediaTime = track->media_time;
|
||||
mTrackId = track->track_id;
|
||||
|
||||
@ -260,7 +262,7 @@ MP4VideoInfo::Update(const mp4parse_track_info* track,
|
||||
mMimeType = NS_LITERAL_CSTRING("video/vp9");
|
||||
}
|
||||
mTrackId = track->track_id;
|
||||
mDuration = track->duration;
|
||||
mDuration = TimeUnit::FromMicroseconds(track->duration);
|
||||
mMediaTime = track->media_time;
|
||||
mDisplay.width = video->display_width;
|
||||
mDisplay.height = video->display_height;
|
||||
|
@ -30,6 +30,7 @@
|
||||
struct FreeMP4Parser { void operator()(mp4parse_parser* aPtr) { mp4parse_free(aPtr); } };
|
||||
|
||||
using namespace stagefright;
|
||||
using mozilla::media::TimeUnit;
|
||||
|
||||
namespace mp4_demuxer
|
||||
{
|
||||
@ -726,10 +727,10 @@ MP4MetadataStagefright::GetTrackInfo(mozilla::TrackInfo::TrackType aType,
|
||||
if (e) {
|
||||
metaData = mMetadataExtractor->getMetaData();
|
||||
int64_t movieDuration;
|
||||
if (!e->mDuration &&
|
||||
if (!e->mDuration.IsPositive() &&
|
||||
metaData->findInt64(kKeyMovieDuration, &movieDuration)) {
|
||||
// No duration in track, use movie extend header box one.
|
||||
e->mDuration = movieDuration;
|
||||
e->mDuration = TimeUnit::FromMicroseconds(movieDuration);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1076,11 +1077,11 @@ MP4MetadataRust::GetTrackInfo(mozilla::TrackInfo::TrackType aType,
|
||||
}
|
||||
|
||||
// No duration in track, use fragment_duration.
|
||||
if (e && !e->mDuration) {
|
||||
if (e && !e->mDuration.IsPositive()) {
|
||||
mp4parse_fragment_info info;
|
||||
auto rv = mp4parse_get_fragment_info(mRustParser.get(), &info);
|
||||
if (rv == mp4parse_status_OK) {
|
||||
e->mDuration = info.fragment_duration;
|
||||
e->mDuration = TimeUnit::FromMicroseconds(info.fragment_duration);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -315,7 +315,8 @@ TEST(stagefright_MPEG4Metadata, test_case_mp4)
|
||||
ASSERT_TRUE(!!videoInfo);
|
||||
EXPECT_TRUE(videoInfo->IsValid());
|
||||
EXPECT_TRUE(videoInfo->IsVideo());
|
||||
EXPECT_EQ(tests[test].mVideoDuration, videoInfo->mDuration);
|
||||
EXPECT_EQ(tests[test].mVideoDuration,
|
||||
videoInfo->mDuration.ToMicroseconds());
|
||||
EXPECT_EQ(tests[test].mWidth, videoInfo->mDisplay.width);
|
||||
EXPECT_EQ(tests[test].mHeight, videoInfo->mDisplay.height);
|
||||
|
||||
@ -339,9 +340,11 @@ TEST(stagefright_MPEG4Metadata, test_case_mp4)
|
||||
ASSERT_TRUE(!!audioInfo);
|
||||
EXPECT_TRUE(audioInfo->IsValid());
|
||||
EXPECT_TRUE(audioInfo->IsAudio());
|
||||
EXPECT_EQ(tests[test].mAudioDuration, audioInfo->mDuration);
|
||||
EXPECT_EQ(tests[test].mAudioDuration,
|
||||
audioInfo->mDuration.ToMicroseconds());
|
||||
EXPECT_EQ(tests[test].mAudioProfile, audioInfo->mProfile);
|
||||
if (tests[test].mAudioDuration != audioInfo->mDuration) {
|
||||
if (tests[test].mAudioDuration !=
|
||||
audioInfo->mDuration.ToMicroseconds()) {
|
||||
MOZ_RELEASE_ASSERT(false);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user