From 44e1b960e14c31e395199eea4e42b81dfcc7f629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez=20Moreno?= Date: Thu, 21 Dec 2017 18:19:51 +0100 Subject: [PATCH] Implement SourceBuffer::AbortBufferAppend and expose ResetParserState through FFI --- gecko-media/gecko/glue/SourceBuffer.cpp | 16 +++++++++++++++ .../glue/include/GeckoMediaSourceBuffer.h | 6 ++++++ gecko-media/gecko/glue/include/SourceBuffer.h | 6 ++++-- gecko-media/src/mse/sourcebuffer.rs | 20 +++++++++++++++++-- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/gecko-media/gecko/glue/SourceBuffer.cpp b/gecko-media/gecko/glue/SourceBuffer.cpp index 216f55b..34a8861 100644 --- a/gecko-media/gecko/glue/SourceBuffer.cpp +++ b/gecko-media/gecko/glue/SourceBuffer.cpp @@ -178,6 +178,22 @@ SourceBuffer::CheckEndTime() } } +void +SourceBuffer::AbortBufferAppend() +{ + MOZ_ASSERT(NS_IsMainThread()); + + if (mCurrentAttributes.GetUpdating()) { + mCompletionPromise.DisconnectIfExists(); + if (mPendingAppend.Exists()) { + mPendingAppend.Disconnect(); + mTrackBuffersManager->AbortAppendData(); + } + + mCurrentAttributes.SetUpdating(false); + } +} + void SourceBuffer::ResetParserState() { diff --git a/gecko-media/gecko/glue/include/GeckoMediaSourceBuffer.h b/gecko-media/gecko/glue/include/GeckoMediaSourceBuffer.h index 7801f8c..3bb8a90 100644 --- a/gecko-media/gecko/glue/include/GeckoMediaSourceBuffer.h +++ b/gecko-media/gecko/glue/include/GeckoMediaSourceBuffer.h @@ -97,6 +97,12 @@ GeckoMedia_SourceBuffer_AppendData(size_t aId, void* aSuccessCbContext, error_callback_t aErrorCb, void* aErrorCbContext); + +void +GeckoMedia_SourceBuffer_AbortBufferAppend(size_t aId); + +void +GeckoMedia_SourceBuffer_ResetParserState(size_t aId); } #endif // GeckoMediaSourceBuffer_h_ \ No newline at end of file diff --git a/gecko-media/gecko/glue/include/SourceBuffer.h b/gecko-media/gecko/glue/include/SourceBuffer.h index f4c72d5..9bcf8e5 100644 --- a/gecko-media/gecko/glue/include/SourceBuffer.h +++ b/gecko-media/gecko/glue/include/SourceBuffer.h @@ -38,13 +38,15 @@ class SourceBuffer final error_callback_t aErrorCb, void* aErrorCbContext); + void AbortBufferAppend(); + + void ResetParserState(); + private: friend class MediaSource; ~SourceBuffer(){}; - void ResetParserState(); - // If the media segment contains data beyond the current duration, // then run the duration change algorithm with new duration set to the // maximum of the current duration and the group end timestamp. diff --git a/gecko-media/src/mse/sourcebuffer.rs b/gecko-media/src/mse/sourcebuffer.rs index 58c521b..77a234b 100644 --- a/gecko-media/src/mse/sourcebuffer.rs +++ b/gecko-media/src/mse/sourcebuffer.rs @@ -2,8 +2,10 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -use bindings::{GeckoMediaSourceBufferImpl, GeckoMedia_SourceBuffer_Create}; -use bindings::{GeckoMedia_SourceBuffer_AppendData, GeckoMedia_SourceBuffer_EvictData}; +use bindings::GeckoMediaSourceBufferImpl; +use bindings::GeckoMedia_SourceBuffer_ResetParserState; +use bindings::{GeckoMedia_SourceBuffer_AbortBufferAppend, GeckoMedia_SourceBuffer_AppendData}; +use bindings::{GeckoMedia_SourceBuffer_Create, GeckoMedia_SourceBuffer_EvictData}; use std::ffi::CString; use std::os::raw::c_void; use std::rc::Rc; @@ -80,6 +82,20 @@ impl SourceBuffer { } } + + pub fn abort_buffer_append(&self) { + let id = self.id; + self.gecko_media.queue_task(move || unsafe { + GeckoMedia_SourceBuffer_AbortBufferAppend(id); + }); + } + + pub fn reset_parser_state(&self) { + let id = self.id; + self.gecko_media.queue_task(move || unsafe { + GeckoMedia_SourceBuffer_ResetParserState(id); + }); + } } impl_drop_gecko_media_struct!(SourceBuffer, GeckoMedia_SourceBuffer_Shutdown);