This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
This document is not complete. It is subject to major changes and, while early experimentations are encouraged, it is therefore not intended for implementation. The Media Capture Task Force expects this specification to evolve significantly based on:
This document was published by the Media Capture Task Force as an Editor's Draft. If you wish to make comments regarding this document, please send them to public-media-capture@w3.org (subscribe, archives). All feedback is welcome.
Publication as an Editor's Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures (Web Real-Time Communication Working Group, Device APIs Working Group) made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This proposal attempts to make basic recording very simple, while still allowing for more complex use cases. In the simplest case, the application instatiates the MediaRecorder object, calls record() and then calls stopRecord() or waits for the MediaStream to be ended. The contents of the recording will be made available in the platform's default encoding via the dataavailable event. Functions are available to query the platform's available set of encodings, and to select the desired ones if the author wishes. The application can also choose how much data it wants to receive at one time. By default a Blob containing the entire recording is returned when the recording finishes. However the application can choose to receive smaller buffers of data at regular intervals.
[Constructor (MediaStream stream)] interface MediaRecorder : EventTarget { readonly attributeMediaStream
stream; readonly attributeRecordingState
state; attributeEventHandler
onrecording; attributeEventHandler
onstop; attributeEventHandler
ondataavailable; attributeEventHandler
onpause; attributeEventHandler
onresume; attributeEventHandler
onmutetrack; attributeEventHandler
onunmutetrack; attributeEventHandler
onphoto; attributeEventHandler
onerror; attributeEventHandler
onwarning; void record (optional long timeSlice); void stop (); void pause(); void resume(); void muteTrack(DOMString trackID); void unmuteTrack(DOMString trackID); void takePhoto(DOMString trackID); void requestData(); AvailableRecordingFormats getOptions (); void setOptions (RecordingFormat RequestedFormats); };
The MediaRecorder()
constructor takes one argument which
must be of type MediaStream
(see Media-Capture). When the constructor
is invoked, the UA must construct a new MediaRecorder
object,
set its mediaStream attribute to be the provided MediaStream, set its state attribute to 'inactive'
and return the object.
stream
of type MediaStream
, readonlyThe MediaStream passed in to the constructor.
state
of type Recordingstate
, readonlyThe current state of the MediaRecorder object.
onrecording
of type EventHandler
Called to handle the recording event.
onstop
of type EventHandler
Called to handle the stop event.
ondataavailable
of type EventHandler
Called to handle the dataavailable event. Note that the Blob (see FILEAPI) of recorded data is contained in this event and can be accessed via the 'data' attribute.
onpause
of type EventHandler
Called to handle the pause event.
onresume
of type EventHandler
Called to handle the resume event.
onmutetrackrecording
of type EventHandler
Called to handle the mutetrackrecording event.
onunmutetrackrecording
of type EventHandler
Called to handle the unmutetrackrecording event.
onphoto
of type EventHandler
Called to handle the photo event. The photo event returns a photo (as a Blob) in a compressed format (for example: PNG/JPEG) rather than a raw ImageData object due to the expected large, uncompressed size of the resulting photos.
onerror
of type EventHandler
Called to handle the recordingerror event.
onwarning
of type EventHandler
Called to handle the recordingwarning event.
record
When a
object’s MediaRecorder
record()
method is invoked,
then, if the state is not "inactive", the UA must
raise an INVALID_STATE
exception and return immediately. Otherwise, it must queue a task, using the DOM manipulation task source, that runs the following steps:
recording
event and start gathering the
data into a Blob (see FILEAPI). timeSlice
argument has been provided, then once timeSlice
milliseconds of data have been colleced, raise a dataavailable
event containing
the Blob of collected data, and start gathering a new Blob of data. Otherwise (if timeSlice
has not been provided), continue gathering data into the original Blob.dataavailable
event containing the Blob of data.stoprecording
event.Note that stop()
,
requestData()
, pause
,
and muteTrack
also affect the recording behavior.
The UA must record the MediaStream
in such a way that the original Tracks can be retrieved at playback time. If any Track within the
MediaStream is muted at any time (i.e., if its readyState
is set to muted
), the UA
must insert black frames or silence until the Track is unmuted. If the UA is
unable to start recording or at any point is unable to contine recording, it must raise
a recordingerror
event, follwowed by a dataavailable
event containing
the Blob it has gathered, follwed by the stoprecording
event.
stop
When a
object’s MediaRecorder
stopRecording
method is invoked,
then if state
is "inactive", the user agent must
raise an INVALID_STATE exception and return immediately. Otherwise it must
queue a task, using the DOM manipulation task source, that runs the following steps:
dataavailable
event containing the Blob of data that has been gathered.recordingdone
eventrequestData
When a
object’s MediaRecorder
requestData()
method is invoked,
then if state
is not "recording"
the user agent must raise an INVALID_STATE exception
and return immediately. Otherwise it must
queue a task, using the DOM manipulation task source, that runs the following steps:
dataavailable
event containing the current Blob of saved data.pause
When a
object’s MediaRecorder
pause()
method is invoked,
then if state
is "inactive"
the user agent must raise an INVALID_STATE exception
and return immediately. Otherwise it must
queue a task, using the DOM manipulation task source, that runs the following steps:
state
to "paused".pause
event resume
When a
object’s MediaRecorder
resume()
method is invoked,
then if state
is "inactive"
the user agent must raise an INVALID_STATE exception
and return immediately. Otherwise it must
queue a task, using the DOM manipulation task source, that runs the following steps:
state
to "recording".resume
event.muteTrack
When a
object’s MediaRecorder
muteTrack()
method is invoked,
then if state
is not "recording"
the user agent must raise an INVALID_STATE exception
and return immediately. Otherwise if the trackID
provided is not the
id
of a Track object in stream
's audioTrackList
or videoTrackList
it must raise an INVALID_TRACK_ID exception
and return immediately. Otherwise it must
queue a task, using the DOM manipulation task source, that runs the following steps:
mutetrackrecording
event.unmuteTrack
When a
object’s MediaRecorder
unmuteTrack()
method is invoked,
then if state
is not "recording",
the user agent must raise an INVALID_STATE exception
and return immediately. Otherwise if the trackID
provided is not the
id
of a Track object in stream
's audioTrackList
or videoTrackList
it must raise an INVALID_TRACK_ID exception
and return immediately. Otherwise it must
queue a task, using the DOM manipulation task source, that runs the following steps:
unmutetrackrecording
event.takePhoto
When a
object’s MediaRecorder
takePhoto()
method is invoked,
then if the trackID
provided is not the
id
of a Track object in stream
's videoTrackList
whose readyState
is "live", the UA must raise an INVALID_TRACK_ID exception
and return immediately. Otherwise it must
queue a task, using the DOM manipulation task source, that runs the following steps:
mute
and unmute
events to fire on the Track in question. photo
event containing the Blob.getOptions
When a
object’s MediaRecorder
getOptions()
method is invoked,
the user agent must return a
availableRecordingFormats structure
containing the set of recording formats that it supports.
setOptions
When a
object’s MediaRecorder
setOptions()
method is invoked,
then if state
requestedFormats
argument,
if the UA does not support it, raise a UNSUPPORTED_OPTION exception, set encodings
back to its value in step 2, and terminate these steps. Otherwise
replace the corresponding member of encodings with the specified value.enum RecordingState {
"inactive",
"recording",
"paused",
};
Enumeration description | |
---|---|
inactive | Recording is not occuring. (Either it has not been started or it has been stopped.) |
recording | Recording has been started and he UA is capturing data. |
paused | Recording has been started, then paused, and not yet stopped or resumed. |
BlobEvent interface
[Constructor(DOMString type, optional BlobEventInit blobInitDict)]
interface BlobEvent : Event {
readonly attribute Blob data;
};
data
of type Blob, readonly<img>
tag.
BlobEventInit dictionary
dictionary BlobEventInit : EventInit {
Blob data;
};
BlobEventInit
Membersdata
of type BlobAvailableRecordingFormats
dictionary AvailableRecordingFormats {
sequence<DOMString> containerEncodingFormats;
sequence<DOMString> audioEncodingFormats;
sequence<DOMString> videoEncodingFormats;
};
containerEncodingFormats
of type sequence<DOMtring>
A list of the container encoding formats that the platform supports.
audioEncodingFormats
of type sequence<DOMtring>
A list of the audio encoding formats that the platform supports.
videoEncodingFormats
of type sequence<DOMtring>
A list of the video encoding formats that the platform supports.
The UA must be able to play back any encoding format that it can record into. The UA must support a container format capable of holding at least two video Tracks and two audio Tracks.
RecordingFormat
dictionary RecordingFormat {
<DOMString> containerEncodingFormat;
<DOMString> audioEncodingFormat;
<DOMString> videoEncodingFormat;
};
containerEncodingFormat
of type <DOMtring>
The container encoding format to use for recording. If it is not specified, the platform default will be used.
audioEncodingFormat
of type <DOMtring>
The audio encoding format to use for recording. If it is not specified, the platform default will be used.
videoEncodingFormat
of type <DOMtring>
The video encoding format to use for recording. If it is not specified, the platform default will be used.
Errors are indicated in two ways: exceptions and objects passed to
error callbacks. Both forms of error reporting must provide an object
of type RecordingError
. An exception must be thrown in the
following cases:
RecordingExceptionName
enum must be used as the error
name.INVALID_STATE
must be used as the error name.In all other cases, an error object must be provided to the failure
callback. The error name in the object provided must be picked from
the RecordingErrorName
enums. After raising the error, the UA must
raise a dataavailable event, containing any data that it has gathered,
and then a recordingdone event. The UA may set platform-specific
limits, such those for the minimum and maximum Blob size that it will support, or the number of
Tracks it will record at once. It must signal a fatal
error if these limits are exceeded. If a non-fatal error occurs during recording, the UA
should raise a recordingwarning event, with data indicating
the nature of the problem, and continue recording.
interface RecordingError {
readonly attribute DOMString name;
readonly attribute DOMString? message;
};
message
of type DOMString, readonly, nullablename
of type DOMString, readonlyRecordingExceptionName
or
RecordingErrorName
enums for the error object to be
valid.enum RTCExceptionName {
"INVALID_MEDIASTREAM_TRACK_ID",
"INVALID_STATE"
"UNSUPPORTED_OPTION"
};
Enumeration description | |
---|---|
INVALID_MEDIASTREAM_TRACK_ID | The argument provided is not the ID of any
MediaStreamTrack belonging to the Media Recorder 's stream . |
INVALID_STATE | The function was called on a MediaRecorder that
is an invalid state, or a state in which the function is not allowed
to be executed. |
UNSUPPORTED_OPTION | The UA cannot provide the codec or recording option that has been requested. |
enum RecordingErrorName {
"OUT_OF_MEMORY",
"ILLEGAL_STREAM_MODIFICATION"
"OTHER_RECORDING_ERROR"
};
Enumeration description | |
---|---|
OUT_OF_MEMORY | The UA has exhaused the available memory. User agents should provide as much additional information in the error message as possible. |
ILLEGAL_STREAM_MODIFICATION | A modification to
the stream has occurred that makes it impossible to continue recording.
An example would be the addition of a Track while recording is occurring. User agents should provide as much additional information in
the error message as possible. |
OTHER_RECORDING_ERROR | Used for an fatal error other than those listed above. User agents should provide as much additional information in the error message as possible. |
The following additional events fire on
objects:MediaRecorder
Event name | Interface | Fired when... |
---|---|---|
recording |
Event |
The UA has started recording data on the MediaStream. |
stoprecording |
Event |
The UA has stopped recording data on the MediaStream. |
dataavailable |
BlobEvent |
The UA generates this even to return data to the application. The 'data' attribute of this event contains a Blob of recorded data. |
photo |
BlobEvent |
The UA uses this event to return a photo to the application (as a Blob). The 'data' attribute of this event contains a Blob of recorded snapshot data. |
pause |
Event |
The UA has paused recording data on the MediaStream. |
resume |
MediaSteamEvent |
The UA has resumed recording data on the MediaStream. |
mutetrackrecording |
MediaSteamTrackEvent |
The MediaRecorder has muted recording on a Track. |
unmutetrackrecording |
MediaSteamTrackEvent |
The MediaRecorder has unmuted recording on a Track. |
recordingerror |
RecordingError |
A fatal error has occurred and the UA has stopped recording. More detailed error information is available in the 'message' attribute. |
recordingwarning |
CustomEvent |
A problem has occurred, but the UA has not stopped recording. More detailed information is available in the 'message' attribute. [Not clear if we need this event.] |