gecko-dev/dom/media/MediaRecorder.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

185 строки
7.0 KiB
C
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
#ifndef MediaRecorder_h
#define MediaRecorder_h
#include "mozilla/dom/MediaRecorderBinding.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/MozPromise.h"
#include "nsIDocumentActivity.h"
// Max size for allowing queue encoded data in memory
#define MAX_ALLOW_MEMORY_BUFFER 1024000
namespace mozilla {
Bug 1454998 - Rename streams to tracks. r=padenot,karlt,smaug This renames the following (in alphabetical order, non-exhaustive): AudioCaptureStream -> AudioCaptureTrack AudioNodeStream -> AudioNodeTrack AudioNodeExternalInputStream -> AudioNodeExternalInputTrack DirectMediaStreamTrackListener -> DirectMediaTrackListener MediaStream -> MediaTrack - Note that there's also dom::MediaTrack. Namespaces differentiate them. MediaStreamGraph -> MediaTrackGraph MediaStreamTrackListener -> MediaTrackListener MSG -> MTG (in comments) ProcessedMediaStream -> ProcessedMediaTrack SharedDummyStream -> SharedDummyTrack SourceMediaStream -> SourceMediaTrack StreamTime -> TrackTime TrackUnionStream -> ForwardedInputTrack - Because this no longer takes a union of anything, but only a single track as input. Other minor classes, members and comments have been updated to reflect these name changes. Differential Revision: https://phabricator.services.mozilla.com/D46146 --HG-- rename : dom/media/AudioCaptureStream.cpp => dom/media/AudioCaptureTrack.cpp rename : dom/media/AudioCaptureStream.h => dom/media/AudioCaptureTrack.h rename : dom/media/TrackUnionStream.cpp => dom/media/ForwardedInputTrack.cpp rename : dom/media/TrackUnionStream.h => dom/media/ForwardedInputTrack.h rename : dom/media/MediaStreamGraph.cpp => dom/media/MediaTrackGraph.cpp rename : dom/media/MediaStreamGraph.h => dom/media/MediaTrackGraph.h rename : dom/media/MediaStreamGraphImpl.h => dom/media/MediaTrackGraphImpl.h rename : dom/media/MediaStreamListener.cpp => dom/media/MediaTrackListener.cpp rename : dom/media/MediaStreamListener.h => dom/media/MediaTrackListener.h rename : dom/media/webaudio/AudioNodeExternalInputStream.cpp => dom/media/webaudio/AudioNodeExternalInputTrack.cpp rename : dom/media/webaudio/AudioNodeExternalInputStream.h => dom/media/webaudio/AudioNodeExternalInputTrack.h rename : dom/media/webaudio/AudioNodeStream.cpp => dom/media/webaudio/AudioNodeTrack.cpp rename : dom/media/webaudio/AudioNodeStream.h => dom/media/webaudio/AudioNodeTrack.h extra : moz-landing-system : lando
2019-10-02 13:23:02 +03:00
class AudioNodeTrack;
class DOMMediaStream;
class ErrorResult;
struct MediaRecorderOptions;
class GlobalObject;
namespace dom {
class AudioNode;
class Blob;
class Document;
class DOMException;
/**
* Implementation of
* https://dvcs.w3.org/hg/dap/raw-file/default/media-stream-capture/MediaRecorder.html
* The MediaRecorder accepts a mediaStream as input source passed from UA. When
* recorder starts, a MediaEncoder will be created and accept the mediaStream as
* input source. Encoder will get the raw data by track data changes, encode it
* by selected MIME Type, then store the encoded in a MutableBlobStorage object.
* The encoded data will be extracted on every timeslice passed from Start
* function call or by RequestData function. Thread model: When the recorder
* starts, it creates a "Media Encoder" thread to read data from MediaEncoder
* object and store buffer in MutableBlobStorage object. Also extract the
* encoded data and create blobs on every timeslice passed from start function
* or RequestData function called by UA.
*/
class MediaRecorder final : public DOMEventTargetHelper,
public nsIDocumentActivity {
public:
class Session;
explicit MediaRecorder(nsPIDOMWindowInner* aOwnerWindow);
static nsTArray<RefPtr<Session>> GetSessions();
// nsWrapperCache
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaRecorder, DOMEventTargetHelper)
// WebIDL
// Start recording. If timeSlice has been provided, mediaRecorder will
// raise a dataavailable event containing the Blob of collected data on every
// timeSlice milliseconds. If timeSlice isn't provided, UA should call the
// RequestData to obtain the Blob data, also set the mTimeSlice to zero.
void Start(const Optional<uint32_t>& timeSlice, ErrorResult& aResult);
// Stop the recording activiy. Including stop the Media Encoder thread,
// un-hook the mediaStreamListener to encoder.
void Stop(ErrorResult& aResult);
// Pause a recording.
void Pause(ErrorResult& aResult);
// Resume a paused recording.
void Resume(ErrorResult& aResult);
// Extract encoded data Blob from MutableBlobStorage.
void RequestData(ErrorResult& aResult);
// Return the The DOMMediaStream passed from UA.
DOMMediaStream* Stream() const { return mStream; }
// Return the current encoding MIME type selected by the MediaEncoder.
void GetMimeType(nsString& aMimeType);
// The current state of the MediaRecorder object.
RecordingState State() const { return mState; }
static bool IsTypeSupported(GlobalObject& aGlobal,
const nsAString& aMIMEType);
static bool IsTypeSupported(const nsAString& aMIMEType);
// Construct a recorder with a DOM media stream object as its source.
static already_AddRefed<MediaRecorder> Constructor(
const GlobalObject& aGlobal, DOMMediaStream& aStream,
const MediaRecorderOptions& aOptions, ErrorResult& aRv);
// Construct a recorder with a Web Audio destination node as its source.
static already_AddRefed<MediaRecorder> Constructor(
const GlobalObject& aGlobal, AudioNode& aAudioNode,
uint32_t aAudioNodeOutput, const MediaRecorderOptions& aOptions,
ErrorResult& aRv);
/*
* Measure the size of the buffer, and heap memory in bytes occupied by
* mAudioEncoder and mVideoEncoder.
*/
typedef MozPromise<size_t, size_t, true> SizeOfPromise;
RefPtr<SizeOfPromise> SizeOfExcludingThis(
mozilla::MallocSizeOf aMallocSizeOf);
// EventHandler
IMPL_EVENT_HANDLER(start)
IMPL_EVENT_HANDLER(stop)
IMPL_EVENT_HANDLER(dataavailable)
IMPL_EVENT_HANDLER(pause)
IMPL_EVENT_HANDLER(resume)
IMPL_EVENT_HANDLER(error)
NS_DECL_NSIDOCUMENTACTIVITY
uint32_t AudioBitsPerSecond() const { return mAudioBitsPerSecond; }
uint32_t VideoBitsPerSecond() const { return mVideoBitsPerSecond; }
protected:
virtual ~MediaRecorder();
MediaRecorder& operator=(const MediaRecorder& x) = delete;
// Create dataavailable event with Blob data and it runs in main thread
nsresult CreateAndDispatchBlobEvent(Blob* aBlob);
// Creating a simple event to notify UA simple event.
void DispatchSimpleEvent(const nsAString& aStr);
// Creating a error event with message.
void NotifyError(nsresult aRv);
MediaRecorder(const MediaRecorder& x) = delete; // prevent bad usage
// Remove session pointer.
void RemoveSession(Session* aSession);
// Create DOMExceptions capturing the JS stack for async errors. These are
// created ahead of time rather than on demand when firing an error as the JS
// stack of the operation that started the async behavior will not be
// available at the time the error event is fired. Note, depending on when
// this is called there may not be a JS stack to capture.
void InitializeDomExceptions();
// Runs the "Inactivate the recorder" algorithm.
void Inactivate();
// Stop the recorder and its internal session. This should be used by
// sessions that are in the process of being destroyed.
void StopForSessionDestruction();
// DOM wrapper for source media stream. Will be null when input is audio node.
RefPtr<DOMMediaStream> mStream;
// Source audio node. Will be null when input is a media stream.
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
RefPtr<AudioNode> mAudioNode;
// Source audio node's output index. Will be zero when input is a media
// stream.
uint32_t mAudioNodeOutput = 0;
// The current state of the MediaRecorder object.
RecordingState mState = RecordingState::Inactive;
// Hold the sessions reference and clean it when the DestroyRunnable for a
// session is running.
Bug 1207245 - part 6 - rename nsRefPtr<T> to RefPtr<T>; r=ehsan; a=Tomcat The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
2015-10-18 08:24:48 +03:00
nsTArray<RefPtr<Session>> mSessions;
RefPtr<Document> mDocument;
nsString mMimeType;
nsString mConstrainedMimeType;
uint32_t mAudioBitsPerSecond = 0;
uint32_t mVideoBitsPerSecond = 0;
Maybe<uint32_t> mConstrainedBitsPerSecond;
// DOMExceptions that are created early and possibly thrown in NotifyError.
// Creating them early allows us to capture the JS stack for which cannot be
// done at the time the error event is fired.
RefPtr<DOMException> mSecurityDomException;
RefPtr<DOMException> mUnknownDomException;
private:
// Register MediaRecorder into Document to listen the activity changes.
void RegisterActivityObserver();
void UnRegisterActivityObserver();
bool CheckPermission(const nsString& aType);
};
} // namespace dom
} // namespace mozilla
#endif