2013-07-05 01:50:25 +00:00
|
|
|
/* -*- 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"
|
2014-04-01 06:13:50 +00:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2014-06-19 02:11:34 +00:00
|
|
|
#include "nsIDocumentActivity.h"
|
2013-07-05 01:50:25 +00:00
|
|
|
|
|
|
|
// Max size for allowing queue encoded data in memory
|
|
|
|
#define MAX_ALLOW_MEMORY_BUFFER 1024000
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class ErrorResult;
|
2013-09-05 20:25:17 +00:00
|
|
|
class DOMMediaStream;
|
|
|
|
class EncodedBufferCache;
|
|
|
|
class MediaEncoder;
|
|
|
|
class ProcessedMediaStream;
|
|
|
|
class MediaInputPort;
|
2014-03-19 06:52:45 +00:00
|
|
|
struct MediaRecorderOptions;
|
2013-07-05 01:50:25 +00:00
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 EncodedBufferCache 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 EncodedBufferCache object.
|
|
|
|
* Also extract the encoded data and create blobs on every timeslice passed from start function or RequestData function called by UA.
|
|
|
|
*/
|
|
|
|
|
2014-06-19 02:11:34 +00:00
|
|
|
class MediaRecorder : public DOMEventTargetHelper,
|
|
|
|
public nsIDocumentActivity
|
2013-07-05 01:50:25 +00:00
|
|
|
{
|
2013-09-26 13:40:40 +00:00
|
|
|
class Session;
|
2014-03-15 19:00:17 +00:00
|
|
|
friend class CreateAndDispatchBlobEventRunnable;
|
2013-09-26 13:40:40 +00:00
|
|
|
|
2013-07-05 01:50:25 +00:00
|
|
|
public:
|
2014-01-07 02:53:23 +00:00
|
|
|
MediaRecorder(DOMMediaStream&, nsPIDOMWindow* aOwnerWindow);
|
2013-07-05 01:50:25 +00:00
|
|
|
|
|
|
|
// nsWrapperCache
|
2014-04-08 22:27:18 +00:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-07-05 01:50:25 +00:00
|
|
|
|
|
|
|
nsPIDOMWindow* GetParentObject() { return GetOwner(); }
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaRecorder,
|
2014-04-01 06:13:50 +00:00
|
|
|
DOMEventTargetHelper)
|
2013-07-05 01:50:25 +00:00
|
|
|
|
|
|
|
// 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<int32_t>& timeSlice, ErrorResult & aResult);
|
|
|
|
// Stop the recording activiy. Including stop the Media Encoder thread, un-hook the mediaStreamListener to encoder.
|
|
|
|
void Stop(ErrorResult& aResult);
|
2013-07-14 07:31:59 +00:00
|
|
|
// Pause the mTrackUnionStream
|
|
|
|
void Pause(ErrorResult& aResult);
|
|
|
|
|
|
|
|
void Resume(ErrorResult& aResult);
|
2013-07-05 01:50:25 +00:00
|
|
|
// Extract encoded data Blob from EncodedBufferCache.
|
|
|
|
void RequestData(ErrorResult& aResult);
|
|
|
|
// Return the The DOMMediaStream passed from UA.
|
|
|
|
DOMMediaStream* Stream() const { return mStream; }
|
|
|
|
// The current state of the MediaRecorder object.
|
|
|
|
RecordingState State() const { return mState; }
|
|
|
|
// Return the current encoding MIME type selected by the MediaEncoder.
|
2013-09-26 13:40:40 +00:00
|
|
|
void GetMimeType(nsString &aMimeType);
|
2013-07-05 01:50:25 +00:00
|
|
|
|
|
|
|
static already_AddRefed<MediaRecorder>
|
2013-08-23 05:17:08 +00:00
|
|
|
Constructor(const GlobalObject& aGlobal,
|
2014-03-19 06:52:45 +00:00
|
|
|
DOMMediaStream& aStream,
|
|
|
|
const MediaRecorderOptions& aInitDict,
|
|
|
|
ErrorResult& aRv);
|
2013-07-05 01:50:25 +00:00
|
|
|
|
|
|
|
// EventHandler
|
|
|
|
IMPL_EVENT_HANDLER(dataavailable)
|
|
|
|
IMPL_EVENT_HANDLER(error)
|
2014-06-27 03:07:45 +00:00
|
|
|
IMPL_EVENT_HANDLER(start)
|
2013-07-05 01:50:25 +00:00
|
|
|
IMPL_EVENT_HANDLER(stop)
|
|
|
|
IMPL_EVENT_HANDLER(warning)
|
|
|
|
|
2014-06-19 02:11:34 +00:00
|
|
|
NS_DECL_NSIDOCUMENTACTIVITY
|
|
|
|
|
2013-07-05 01:50:25 +00:00
|
|
|
protected:
|
2014-07-08 21:23:16 +00:00
|
|
|
virtual ~MediaRecorder();
|
|
|
|
|
2013-07-05 01:50:25 +00:00
|
|
|
MediaRecorder& operator = (const MediaRecorder& x) MOZ_DELETE;
|
|
|
|
// Create dataavailable event with Blob data and it runs in main thread
|
2014-03-15 19:00:17 +00:00
|
|
|
nsresult CreateAndDispatchBlobEvent(already_AddRefed<nsIDOMBlob>&& aBlob);
|
2013-07-05 01:50:25 +00:00
|
|
|
// Creating a simple event to notify UA simple event.
|
|
|
|
void DispatchSimpleEvent(const nsAString & aStr);
|
|
|
|
// Creating a error event with message.
|
|
|
|
void NotifyError(nsresult aRv);
|
|
|
|
// Check if the recorder's principal is the subsume of mediaStream
|
|
|
|
bool CheckPrincipal();
|
2013-09-26 13:40:40 +00:00
|
|
|
// Set encoded MIME type.
|
|
|
|
void SetMimeType(const nsString &aMimeType);
|
2013-07-05 01:50:25 +00:00
|
|
|
|
|
|
|
MediaRecorder(const MediaRecorder& x) MOZ_DELETE; // prevent bad usage
|
2014-03-25 17:11:58 +00:00
|
|
|
// Remove session pointer.
|
|
|
|
void RemoveSession(Session* aSession);
|
2013-07-05 01:50:25 +00:00
|
|
|
// MediaStream passed from js context
|
|
|
|
nsRefPtr<DOMMediaStream> mStream;
|
|
|
|
// The current state of the MediaRecorder object.
|
|
|
|
RecordingState mState;
|
2014-06-19 02:11:34 +00:00
|
|
|
// Hold the sessions pointer and clean it when the DestroyRunnable for a
|
|
|
|
// session is running.
|
2014-03-25 17:11:58 +00:00
|
|
|
nsTArray<Session*> mSessions;
|
2013-09-26 13:40:40 +00:00
|
|
|
// It specifies the container format as well as the audio and video capture formats.
|
|
|
|
nsString mMimeType;
|
2014-06-19 02:11:34 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Register MediaRecorder into Document to listen the activity changes.
|
|
|
|
void RegisterActivityObserver();
|
|
|
|
void UnRegisterActivityObserver();
|
2013-07-05 01:50:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|