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.

--HG--
extra : rebase_source : f417b968e81d9c9a1aff8ae3174079a297eb371b
This commit is contained in:
Thomas Zimmermann 2013-05-03 09:48:37 +02:00
parent 9f51b66cc3
commit 21922c6b1f
6 changed files with 34 additions and 0 deletions

View File

@ -72,6 +72,11 @@ public:
// Set the duration of the media in microseconds. // Set the duration of the media in microseconds.
virtual void SetMediaDuration(int64_t aDuration) = 0; 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. // Set the media as being seekable or not.
virtual void SetMediaSeekable(bool aMediaSeekable) = 0; virtual void SetMediaSeekable(bool aMediaSeekable) = 0;

View File

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

View File

@ -506,6 +506,7 @@ public:
virtual void SetDuration(double aDuration); virtual void SetDuration(double aDuration);
void SetMediaDuration(int64_t aDuration) MOZ_OVERRIDE; void SetMediaDuration(int64_t aDuration) MOZ_OVERRIDE;
void UpdateMediaDuration(int64_t aDuration) MOZ_OVERRIDE;
// Set a flag indicating whether seeking is supported // Set a flag indicating whether seeking is supported
virtual void SetMediaSeekable(bool aMediaSeekable) MOZ_OVERRIDE; 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) void MediaDecoderStateMachine::SetMediaEndTime(int64_t aEndTime)
{ {
NS_ASSERTION(OnDecodeThread(), "Should be on decode thread"); NS_ASSERTION(OnDecodeThread(), "Should be on decode thread");

View File

@ -157,6 +157,10 @@ public:
// aEndTime is in microseconds. // aEndTime is in microseconds.
void SetMediaEndTime(int64_t aEndTime); 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 // Functions used by assertions to ensure we're calling things
// on the appropriate threads. // on the appropriate threads.
bool OnDecodeThread() const { bool OnDecodeThread() const {

View File

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