Bug 831224: Allow update of the media duration, r=padenot

With MP3 streams, the media duration might change after we received
new data. This patch adds infrastructure to signal the new duration
to the media decoder and state machine. It will also fire an event
of type 'durationchange' to the DOM.
This commit is contained in:
Thomas Zimmermann 2013-05-03 09:48:37 +02:00
parent 156ef9939c
commit 029ae7c49e
6 changed files with 34 additions and 0 deletions

View File

@ -72,6 +72,11 @@ public:
// Set the duration of the media in microseconds.
virtual void SetMediaDuration(int64_t aDuration) = 0;
// Sets the duration of the media in microseconds. The MediaDecoder
// fires a durationchange event to its owner (e.g., an HTML audio
// tag).
virtual void UpdateMediaDuration(int64_t aDuration) = 0;
// Set the media as being seekable or not.
virtual void SetMediaSeekable(bool aMediaSeekable) = 0;

View File

@ -1272,6 +1272,12 @@ void MediaDecoder::SetMediaDuration(int64_t aDuration)
GetStateMachine()->SetDuration(aDuration);
}
void MediaDecoder::UpdateMediaDuration(int64_t aDuration)
{
NS_ENSURE_TRUE_VOID(GetStateMachine());
GetStateMachine()->UpdateDuration(aDuration);
}
void MediaDecoder::SetMediaSeekable(bool aMediaSeekable) {
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
MOZ_ASSERT(NS_IsMainThread() || OnDecodeThread());

View File

@ -506,6 +506,7 @@ public:
virtual void SetDuration(double aDuration);
void SetMediaDuration(int64_t aDuration) MOZ_OVERRIDE;
void UpdateMediaDuration(int64_t aDuration) MOZ_OVERRIDE;
// Set a flag indicating whether seeking is supported
virtual void SetMediaSeekable(bool aMediaSeekable) MOZ_OVERRIDE;

View File

@ -1446,6 +1446,16 @@ void MediaDecoderStateMachine::SetDuration(int64_t aDuration)
}
}
void MediaDecoderStateMachine::UpdateDuration(int64_t aDuration)
{
if (aDuration != GetDuration()) {
SetDuration(aDuration);
nsCOMPtr<nsIRunnable> event =
NS_NewRunnableMethod(mDecoder, &MediaDecoder::DurationChanged);
NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
}
}
void MediaDecoderStateMachine::SetMediaEndTime(int64_t aEndTime)
{
NS_ASSERTION(OnDecodeThread(), "Should be on decode thread");

View File

@ -157,6 +157,10 @@ public:
// aEndTime is in microseconds.
void SetMediaEndTime(int64_t aEndTime);
// Called from decode thread to update the duration. Can result in
// a durationchangeevent. aDuration is in microseconds.
void UpdateDuration(int64_t aDuration);
// Functions used by assertions to ensure we're calling things
// on the appropriate threads.
bool OnDecodeThread() const {

View File

@ -97,6 +97,8 @@ public:
virtual void SetMediaDuration(int64_t aDuration) MOZ_FINAL MOZ_OVERRIDE;
virtual void UpdateMediaDuration(int64_t aDuration) MOZ_FINAL MOZ_OVERRIDE;
virtual void SetMediaSeekable(bool aMediaSeekable) MOZ_OVERRIDE;
virtual void SetTransportSeekable(bool aTransportSeekable) MOZ_FINAL MOZ_OVERRIDE;
@ -214,6 +216,12 @@ BufferDecoder::SetMediaDuration(int64_t aDuration)
// ignore
}
void
BufferDecoder::UpdateMediaDuration(int64_t aDuration)
{
// ignore
}
void
BufferDecoder::SetMediaSeekable(bool aMediaSeekable)
{