[TCSACR-53][StreamRecorder] Add a guide for the stream recorder. 14/151814/2
authorcoderhyme <jhyo.kim@samsung.com>
Fri, 22 Sep 2017 05:19:51 +0000 (14:19 +0900)
committerEditor Lionbridge <TizenEditor.SEL@lionbridge.com>
Mon, 25 Sep 2017 07:06:47 +0000 (10:06 +0300)
PS2: Reviewed

Change-Id: I07514a8badf28104b2276fe0eea2ebd6c63ea4c5
Signed-off-by: coderhyme <jhyo.kim@samsung.com>
org.tizen.guides/html/dotnet/media/stream_recorder.htm [new file with mode: 0644]
org.tizen.guides/html/images/streamrecorder_states_cs.png [new file with mode: 0644]

diff --git a/org.tizen.guides/html/dotnet/media/stream_recorder.htm b/org.tizen.guides/html/dotnet/media/stream_recorder.htm
new file mode 100644 (file)
index 0000000..635aa11
--- /dev/null
@@ -0,0 +1,204 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+       <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
+       <meta http-equiv="X-UA-Compatible" content="IE=9" />
+       <link rel="stylesheet" type="text/css" href="../../css/styles.css" />
+       <link rel="stylesheet" type="text/css" href="../../css/snippet.css" />
+       <script type="text/javascript" src="../../scripts/snippet.js"></script>
+       <script type="text/javascript" src="../../scripts/jquery.util.js" charset="utf-8"></script>
+       <script type="text/javascript" src="../../scripts/common.js" charset="utf-8"></script>
+       <script type="text/javascript" src="../../scripts/core.js" charset="utf-8"></script>
+       <script type="text/javascript" src="../../scripts/search.js" charset="utf-8"></script>
+
+  <title>Media Stream Recording</title>
+</head>
+
+<body onload="prettyPrint()" style="overflow: auto;">
+
+
+<div id="toc-navigation">
+
+       <div id="toc_border"><div id="toc">
+               <p class="toc-title">Dependencies</p>
+               <ul class="toc">
+                       <li>Tizen 4.0 and Higher</li>
+               </ul>
+
+               <p class="toc-title">Content</p>
+                       <ul class="toc">
+                       <li><a href="#prerequisites">Prerequisites</a></li>
+                       <li><a href="#manage">Managing Recording Options</a></li>
+                       <li><a href="#packet">Creating a Media Packet</a></li>
+                       <li><a href="#record_stream">Recording a Stream</a></li>
+                       </ul>
+
+               <p class="toc-title">Related Info</p>
+               <ul class="toc">
+                       <li><a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Multimedia_1_1StreamRecorder.html">Tizen.Multimedia.StreamRecorder Class</a></li>
+               </ul>
+       </div></div>
+</div>
+
+<div id="container"><div id="contents"><div class="content">
+<h1>Media Stream Recording</h1>
+
+<p>You can record audio and video from a stream, and control the recording process through various settings. With the stream recorder, live audio and video can be kept on your target.</p>
+
+<p>The main features of the <code>Tizen.Multimedia.StreamRecorder</code> class include:</p>
+<ul>
+<li>Creating a media packet
+<p>You must <a href="#packet">create a media packet</a> for the stream recording using raw data from the source. The media packet must be created for each buffer captured from the source and passed to the <code>PushBuffer()</code> method of the <code>Tizen.Multimedia.StreamRecorder</code> class.</p></li>
+<li>Recording audio and video, and controlling the recording
+<p>You can <a href="#record_stream">record a stream, pause, stop, and cancel the recording</a>, and push the buffer.</p>
+</li>
+<li>Managing recording options
+<p>You can <a href="#manage">manage various recording details</a>, such as the bitrate, codec, maximum recording length, and filename:</p>
+<ul>
+<li>You can encode files in various formats:
+<ul>
+<li>Video: MP4 and 3GP</li>
+<li>Audio: AMR, AAC, and WAV</li>
+</ul>
+<p>The supported file formats are defined in the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Multimedia.html#af6f995366abb82b115610e8bebca886c">Tizen.Multimedia.StreamRecorderFileFormat</a> enumeration.</p></li>
+<li>You can use various video and audio encoders.
+<p>The available video and audio codecs are defined in the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Multimedia.html#aee3cc1eff93fd449ec54c9e6442ccc64">Tizen.Multimedia.StreamRecorderVideoCodec</a> and <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Multimedia.html#ac2a9d3752357fdf9bd3f8aab627c7d08">Tizen.Multimedia.StreamRecorderAudioCodec</a> enumerations.</p>
+</li>
+</ul>
+</li>
+
+</ul>
+
+<p>Valid input sources consist of external sources, such as a live buffer passed by the application. Most operations of the stream recorder work synchronously.</p>
+
+<p>The following figure illustrates general stream recorder state changes. Use the stream recorder methods according to pre and post conditions, by following the state changes.</p>
+
+<p align="center"><strong>Figure: Stream recorder state changes</strong></p>
+<p align="center"><img alt="Stream recorder state changes" src="../../images/streamrecorder_states_cs.png" /></p>
+
+<h2 id="prerequisites">Prerequisites</h2>
+
+<p>To use the methods and properties of the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Multimedia_1_1StreamRecorder.html">Tizen.Multimedia.StreamRecorder</a> class, include the <a href="https://developer.tizen.org/dev-guide/csapi/namespaceTizen_1_1Multimedia.html">Tizen.Multimedia</a> namespace in your application:</p>
+<pre class="prettyprint">
+using Tizen.Multimedia;
+</pre>
+
+<h2 id="manage">Managing Recording Options</h2>
+To define recording options for video recording:
+<ol>
+<li><p>Create an instance of the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Multimedia_1_1StreamRecorderOptions.html">Tizen.Multimedia.StreamRecorderOptions</a> class with the output path and file format for the recorded media stream:</p>
+<pre class="prettyprint">
+var options = new StreamRecorderOptions(SavePath, RecorderFileFormat.Mp4);
+</pre>
+<p>You can check which file formats the device supports using the <code>GetSupportedFileFormats()</code> method of the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Multimedia_1_1StreamRecorder_1_1Capabilities.html">Tizen.Multimedia.StreamRecorder.Capabilities</a> class.</p></li>
+<li>Define the video recording options in the <code>Video</code> property of the <code>Tizen.Multimedia.StreamRecorderOptions</code> class, using an instance of the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Multimedia_1_1StreamRecorderVideoOptions.html">Tizen.Multimedia.StreamRecorderVideoOptions</a> class:
+<pre class="prettyprint">
+options.Video = new StreamRecorderVideoOptions(codec: RecorderVideoCodec.H263,
+                                               resolution: new Size(1920, 1080),
+                                               sourceFormat: StreamRecorderVideoFormat.Nv12,
+                                               frameRate: 30,
+                                               bitRate: 288000);
+</pre>
+<p>To get a list of video codecs the device supports, use the <code>GetSupportedVideoEncodings()</code> method of the <code>Tizen.Multimedia.StreamRecorder.Capabilities</code> class. The following example retrieves the first supported codec found:</p>
+<pre class="prettyprint">
+var streamRecorder = new StreamRecorder();
+
+var videoCodec = streamRecorder.Capabilities.GetSupportedVideoEncodings().First();
+</pre>
+<div class="note">
+<strong>Note</strong>
+Even if a higher bitrate is set, the recording bitrate is limited by that of the stream buffer pushed.
+</div>
+</li>
+</ol>
+
+<p>Similarly, to record an audio stream, define the audio recording options in the <code>Audio</code> property of the <code>StreamRecorderOptions</code> class instance, using an instance of the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Multimedia_1_1StreamRecorderAudioOptions.html">Tizen.Multimedia.StreamRecorderAudioOptions</a> class.</p>
+
+<h2 id="packet">Creating a Media Packet</h2>
+
+<p>When the stream recorder is configured, create the media packet using the raw data from the source:</p>
+<pre class="prettyprint">
+byte[] rawbuffer; /// Data to be passed for recording
+
+var videoFormat = new VideoMediaFormat(MediaFormatVideoMimeType.Mpeg4SP, new Size(640, 480));
+var mediaPacket = MediaPacket.Create(videoFormat);
+
+mediaPacket.CopyFrom(rawbuffer, 0, rawbuffer.length);
+</pre>
+<p>The media packet must be created for each buffer captured from the source and passed to the <code>PushBuffer()</code> method of the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Multimedia_1_1StreamRecorder.html">Tizen.Multimedia.StreamRecorder</a> class when the stream recorder is prepared to record.</p>
+
+<h2 id="record_stream">Recording a Stream</h2>
+
+<p>To record a stream:</p>
+<ol>
+<li>Call the <code>Prepare()</code> method of the <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Multimedia_1_1StreamRecorder.html">Tizen.Multimedia.StreamRecorder</a> class with a <a href="https://developer.tizen.org/dev-guide/csapi/classTizen_1_1Multimedia_1_1StreamRecorderOptions.html">Tizen.Multimedia.StreamRecorderOptions</a> instance:
+<pre class="prettyprint">
+streamRecorder.Prepare(options);
+</pre>
+The stream recorder state changes to <code>Ready</code>.
+</li>
+<li>Start recording by calling the <code>Start()</code> method:
+<pre class="prettyprint">
+streamRecorder.Start();
+</pre>
+<p>Once the recording starts, if you set the file path to an existing file, the file is removed automatically and replaced with a new one.</p>
+<p>You can only call the <code>Start()</code> method in the <code>Ready</code> or <code>Paused</code> state. After starting, the state changes to <code>Recording</code>.</p>
+<p>Push the media packet to record audio or video, using the <code>PushBuffer()</code> method:</p>
+<pre class="prettyprint">
+streamRecorder.PushBuffer(mediaPacket);
+</pre>
+</li>
+<li>During the recording, you can pause or stop it:
+<ul>
+<li>To pause recording, use the <code>Pause()</code> method:
+<pre class="prettyprint">
+streamRecorder.Pause();
+</pre>
+<p>The stream recorder state changes from <code>Recording</code> to <code>Paused</code>.</p>
+To resume recording, use the <code>Start()</code> method.
+<p>Alternatively, you can stop pushing the stream buffers. In this case, the stream recorder remains in the <code>Recording</code> state, and continues waiting for buffers. It creates the same effect as a pause in the recording.</p></li>
+<li>To stop recording and save the result, use the <code>Commit()</code> method. The recording result is saved to the file path defined in the <code>Tizen.Multimedia.StreamRecorderOptions</code> instance.
+<pre class="prettyprint">
+streamRecorder.Commit();
+</pre>
+<p>You can only call the <code>Start()</code> method in the <code>Recording</code> or <code>Paused</code> state. After committing, the state changes to <code>Ready</code>.</p></li>
+<li>To stop recording without saving the result, use the <code>Cancel()</code> method.
+<p>The only difference between this method and the <code>Commit()</code> method is that the recording data is not written to the file.</p>
+<pre class="prettyprint">
+streamRecorder.Cancel();
+</pre>
+</li>
+</ul>
+</li>
+<li>When you have finished recording, use the <code>Unprepare()</code> method to reset the stream recorder:
+<pre class="prettyprint">
+streamRecorder.Unprepare();
+</pre>
+<p>The stream recorder state changes from <code>Ready</code> to <code>Idle</code>.</p>
+</li>
+</ol>
+
+<script type="text/javascript" src="../../scripts/jquery.zclip.min.js"></script>
+<script type="text/javascript" src="../../scripts/showhide.js"></script>
+</div></div></div>
+
+
+<a class="top sms" href="#"><img src="../../images/btn_top.gif" alt="Go to top"/></a>
+
+<div id="footer">
+<p class="footer">Except as noted, this content - excluding the Code Examples - is licensed under <a href="http://creativecommons.org/licenses/by/3.0/legalcode" target="_blank">Creative Commons Attribution 3.0</a> and all of the Code Examples contained herein are licensed under <a href="https://www.tizen.org/bsd-3-clause-license" target="_blank">BSD-3-Clause</a>.<br/>For details, see the <a href="https://www.tizen.org/content-license" target="_blank">Content License</a>.</p>
+</div>
+
+<script type="text/javascript">
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', 'UA-25976949-1']);
+_gaq.push(['_trackPageview']);
+(function() {
+var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+})();
+</script>
+
+</body>
+</html>
diff --git a/org.tizen.guides/html/images/streamrecorder_states_cs.png b/org.tizen.guides/html/images/streamrecorder_states_cs.png
new file mode 100644 (file)
index 0000000..c69d38d
Binary files /dev/null and b/org.tizen.guides/html/images/streamrecorder_states_cs.png differ