2.1 demo illustrates
- Danuniu live SDK provides C++/C# two sets of interfaces, external provides 32/64-bit debug/release library, C++ and C# interface one by one, C# interface is added prefix NT_PB_ than C++ interface;
- Win-playersdk-cpp-demo: indicates the Demo of the C++ interface corresponding to the PlayerSDK.
- Win-playersdk-csharp-demo: Demo of the C# interface corresponding to the PlayerSDK;
- The player SDK supports Win7 and above systems;
- This demo is based on VS2013 development.
2.2 UI Display
2.3 Integration Description
C++ header file:
- nT_type_define.h
- [definition Log] smart_log. H
- [definition Log] smart_log_define. H
- [Base code definition]nt_base_code_define.h
- [] player interface smart_player_define. H
- [Player Parameter Definition]smart_player_sdk.h
C# header file:
- [Base code definition]nt_base_code_define.cs
- [] player interface smart_player_define. Cs
- [Player Parameter Definition] smart_player_sdK.cs
Related Lib:
- SmartLog.dll
- SmartLog.lib
- SmartPlayerSDK.dll
- SmartPlayerSDK.lib
- avcodec-56.dll
- avdevice-56.dll
- avfilter-5.dll
- avformat-56.dll
- avutil-54.dll
- postproc-53.dll
- swresample-1.dll
- swscale-3.dll
Integration steps:
- Copy the debug/release library from the lib directory to the corresponding debug or Release directory of the project to be integrated (make sure that the 32-bit and 64-bit library debug/ Release directories correspond one by one).
The lib directory is as follows:
-
- 32-bit Debug library: Debug
- 32-bit release library: release
- 64-bit debug library: x64\debug
- 64-bit release library: x64\release
2. Related CS header files, add projects to be integrated;
3. In the project you want to integrate, right-click ->Properties->
Application->Assembly name, ** SDK is authorized according to the APP name, the unauthorized version, please change this to “SmartPlayer” **, if you need authorization, you can directly contact business;
4. In the official authorization edition, you need to add the code for setting the license before invoking the Init() interface (fill in the related Key and CID according to the email description of the official authorization edition) :
2.4 interface call timing (C# as an example)
2.4.1 Setting an Authorization License
For C# SDK, please add the following code before nt.ntsmartplayersdk.nt_sp_init:
NT.NTSmartPlayerSDK.NT_SP_SetSDKClientKey("xxxxxxxxxx"."xxxxxxxxxx".0, IntPtr.Zero);
UInt32 isInited = NT.NTSmartPlayerSDK.NT_SP_Init(0, IntPtr.Zero);
if(isInited ! =0)
{
MessageBox.Show("Failed to call NT_SP_Init..");
return;
}
Copy the code
C++ SDK, please add the following code before player_api_.Init:
NT_SP_SetSDKClientKey(NT_SP_SetSDKClientKey("xxxxxxxxxx"."xxxxxxxxxx".0.nullptr);
if( NT_ERC_OK ! = player_api_.Init(0.NULL)) {return FALSE;
}
Copy the code
2.4.2 Setting the Log Storage Path
You need to add the following code before player_API_.init:
// Set the log path (make sure the directory exists)
String log_path = "D:\\playerlog";
NTSmartLog.NT_SL_SetPath(log_path);
Copy the code
If the directory exists and has the permission to write files, the smart_sdK. log file will be generated in the related folder after the application program is closed.
2.4.3 Initializing the SDK
NT_SP_Init: SDK initialization, multi-instance play, this interface only needs to be called once.
2.4.4 Hard decoding detection for specific models
If the system is used in a specific model environment, especially in multi-channel playback scenarios, if hard decoding is needed, the following two sets of interfaces can be used to detect whether the system supports hard decoding.
Note: On the premise that the performance of the soft solution meets the system requirements, it is generally recommended to use the soft solution.
/* * Check whether H264 hard decoding is supported * if so, return NT_ERC_OK */
[DllImport(@"SmartPlayerSDK.dll")]
public static extern UInt32 NT_SP_IsSupportH264HardwareDecoder();
/* * Check whether H265 hard decoding is supported * if so, return NT_ERC_OK */
[DllImport(@"SmartPlayerSDK.dll")]
public static extern UInt32 NT_SP_IsSupportH265HardwareDecoder();
Copy the code
To use hard decoding, call the following interface:
NTSmartPlayerSDK.NT_SP_SetH264HardwareDecoder(player_handle_, is_support_h264_hardware_decoder_ ? 1 : 0.0);
NTSmartPlayerSDK.NT_SP_SetH265HardwareDecoder(player_handle_, is_support_h265_hardware_decoder_ ? 1 : 0.0);
Copy the code
2.4.5 Open Generates a playback instance
NT_SP_Open: Each call to the Open interface corresponds to one player instance. If multiple instances are to be played, multiple Player Handlers are required.
if (player_handle_ == IntPtr.Zero)
{
player_handle_ = new IntPtr();
UInt32 ret_open = NTSmartPlayerSDK.NT_SP_Open(out player_handle_, IntPtr.Zero, 0, IntPtr.Zero);
if(ret_open ! =0)
{
player_handle_ = IntPtr.Zero;
MessageBox.Show("Calling NT_SP_Open failed..");
return; }}Copy the code
2.4.6 Setting the Callback Event
- NT_SP_SetEventCallBack: used to call back network connection status, buffer status (start, buffer ratio, end), real-time bandwidth, etc., corresponding to EventID as follows:
/ * event ID * /
public enum NT_SP_E_EVENT_ID : uint
{
NT_SP_E_EVENT_ID_BASE = NTBaseCodeDefine.NT_EVENT_ID_SMART_PLAYER_SDK,
NT_SP_E_EVENT_ID_CONNECTING = NT_SP_E_EVENT_ID_BASE | 0x2./* Connection */
NT_SP_E_EVENT_ID_CONNECTION_FAILED = NT_SP_E_EVENT_ID_BASE | 0x3./* Connection failed */
NT_SP_E_EVENT_ID_CONNECTED = NT_SP_E_EVENT_ID_BASE | 0x4./* Connected */
NT_SP_E_EVENT_ID_DISCONNECTED = NT_SP_E_EVENT_ID_BASE | 0x5./* Disconnect */
NT_SP_E_EVENT_ID_NO_MEDIADATA_RECEIVED = NT_SP_E_EVENT_ID_BASE | 0x8./* Failed to receive RTMP data */
NT_SP_E_EVENT_ID_RTSP_STATUS_CODE = NT_SP_E_EVENT_ID_BASE | 0xB./* RTSP status code Is reported. Currently, only 401 is reported. Param1 indicates status code*/
/* Start at 0x81 */
NT_SP_E_EVENT_ID_START_BUFFERING = NT_SP_E_EVENT_ID_BASE | 0x81./* Start buffer */
NT_SP_E_EVENT_ID_BUFFERING = NT_SP_E_EVENT_ID_BASE | 0x82./* In the buffer, param1 represents the percentage of progress */
NT_SP_E_EVENT_ID_STOP_BUFFERING = NT_SP_E_EVENT_ID_BASE | 0x83./* Stop buffering */
NT_SP_E_EVENT_ID_DOWNLOAD_SPEED = NT_SP_E_EVENT_ID_BASE | 0x91./* Download speed. Param1 indicates the download speed, expressed in Byte/s */
NT_SP_E_EVENT_ID_PLAYBACK_REACH_EOS = NT_SP_E_EVENT_ID_BASE | 0xa1./* When the playback ends, the live stream does not have this event, the on-demand stream only has */
NT_SP_E_EVENT_ID_RECORDER_REACH_EOS = NT_SP_E_EVENT_ID_BASE | 0xa2./* When the video is finished, the live stream does not have this event, the on-demand stream only has */
NT_SP_E_EVENT_ID_PULLSTREAM_REACH_EOS = NT_SP_E_EVENT_ID_BASE | 0xa3./* Pull stream ends, live stream does not have this event, on-demand stream only have */
NT_SP_E_EVENT_ID_DURATION = NT_SP_E_EVENT_ID_BASE | 0xa8./* Video duration. If the video duration is live, it is not reported. If the video duration can be obtained from the video source, it is reported. Param1 indicates the video duration in ms */
}
Copy the code
- NT_SP_SetVideoSizeCallBack: Set the video resolution callback. If the stream data carries video data, the SDK will return the video width and height information:
//video resolution callback
video_size_call_back_ = new SP_SDKVideoSizeCallBack(SP_SDKVideoSizeHandle);
NTSmartPlayerSDK.NT_SP_SetVideoSizeCallBack(player_handle_, IntPtr.Zero, video_size_call_back_);
Copy the code
** Note: ** Call NT_SP_OnWindowSize() when the video width and height return or the drawing window changes, otherwise the video may be blurred.
private void PlaybackWindowResized(Int32 width,Int32 height)
{
width_=width;
height_=height;
int left=playWnd.Left;
int top=playWnd.Top;
textBox_resolution.Text=width+"*"+height;
if(player_handle_==IntPtr.Zero)
{
return;
}
NTSmartPlayerSDK.NT_SP_OnWindowSize(player_handle_,playWnd.Width,playWnd.Height);
}
Copy the code
- NT_SP_SetVideoFrameCallBack: Sets YUV/RGB32 data callback, which can be used for third-party video analysis or self-drawing. If the system does not support D3D drawing, you can set callback data, and upper-layer GDI drawing mode:
/* Define the video frame image format */
public enum NT_SP_E_VIDEO_FRAME_FORMAT : uint
{
NT_SP_E_VIDEO_FRAME_FORMAT_RGB32 = 1.In 32-bit RGB format, r, G, and B are 8 bytes each, and the other byte is reserved. The memory byte format is bb GG RR xx, which mainly matches the Windows bitmap. In small-encoder mode, DWORD operation is performed, and the highest bit is XX, followed by RR, GG, and bb
NT_SP_E_VIDEO_FRAME_FORMAT_ARGB = 2.// 32-bit ARGB format. Memory byte format is bb GG RR AA, which matches Windows bitmap
NT_SP_E_VIDEO_FRAME_FROMAT_I420 = 3.// In YUV420 format, three components are stored on three faces
}
Copy the code
- NT_SP_SetVideoFrameCallBackV2: sets YUV/RGB32 data callback. The difference with NT_SP_SetVideoFrameCallBack interface is that the width and height of the video data can be specified.
- NT_SP_SetRenderVideoFrameTimestampCallBack: set up the rendering video frames, video frame timestamp callback, general player without a timestamp callback requirements, without setting:
//video timestamp callback
video_frame_ts_callback_ = new SP_SDKRenderVideoFrameTimestampCallBack(SP_SDKRenderVideoFrameTimestampCallBack);
NTSmartPlayerSDK.NT_SP_SetRenderVideoFrameTimestampCallBack(player_handle_, IntPtr.Zero, video_frame_ts_callback_);
Copy the code
- NT_SP_SetAudioPCMFrameCallBack: Set audio PCM frame callback, PCM data out, the current size of each frame is 10ms, general player does not need to set;
- NT_SP_SetUserDataCallBack: Set user data callback. This interface needs to work with the push SDK to return real-time user data set by the push server (such as time stamps, latitude and longitude). If only the playback SDK is used, no setting is required.
- NT_SP_SetSEIDataCallBack: Sets the video SEI data callback. This is not required if you are simply using the playback SDK and do not need to process the extended SEI data.
2.4.7 D3DRender detection
At present, D3D drawing is rarely not supported. Considering the universality of the system, we do detection before playing, and the specific call interface is as follows:
*is_support: 1 if it is supported *is_support is 0 if it is not supported * NT_ERC_OK */ is returned on success of the interface call
[DllImport(@"SmartPlayerSDK.dll")]
public static extern UInt32 NT_SP_IsSupportD3DRender(IntPtr handle, IntPtr hwnd, ref Int32 is_support);
Copy the code
In the case that D3D rendering is not supported, YUV data is set to be called back and the upper layer is directly drawn in GDI mode. Note that GDI rendering efficiency is low.
Int32 in_support_d3d_render = 0;
if (NT.NTBaseCodeDefine.NT_ERC_OK == NTSmartPlayerSDK.NT_SP_IsSupportD3DRender(player_handle_, playWnd.Handle, ref in_support_d3d_render))
{
if (1 == in_support_d3d_render)
{
is_support_d3d_render = true; }}if (is_support_d3d_render)
{
is_gdi_render_ = false;
// If you support D3D rendering, use D3D rendering
NTSmartPlayerSDK.NT_SP_SetRenderWindow(player_handle_, playWnd.Handle);
if (btn_check_render_scale_mode.Checked)
{
NTSmartPlayerSDK.NT_SP_SetRenderScaleMode(player_handle_, 1);
}
else
{
NTSmartPlayerSDK.NT_SP_SetRenderScaleMode(player_handle_, 0); }}else
{
is_gdi_render_ = true;
playWnd.Visible = false;
// If D3D is not supported, let the player spit out the data and draw with GDI
//video frame callback (YUV/RGB)
// Format see NT_SP_E_VIDEO_FRAME_FORMAT. If you need to call YUV, set it to NT_SP_E_VIDEO_FRAME_FROMAT_I420
video_frame_call_back_ = new SP_SDKVideoFrameCallBack(SetVideoFrameCallBack);
NTSmartPlayerSDK.NT_SP_SetVideoFrameCallBack(player_handle_, (Int32)NT.NTSmartPlayerDefine.NT_SP_E_VIDEO_FRAME_FORMAT.NT_SP_E_VIDEO_FRAME_FORMAT_RGB32, IntPtr.Zero, video_frame_call_back_);
}
Copy the code
2.4.8 Setting the PLAYING URL
NT_SP_SetURL: supports RTSP/RTMP/local FLV files (full path).
2.4.9 Setting the PCM callback
NT_SP_SetIsOutputAudioDevice: Sets whether to play a sound. This is different from the mute interface. The main purpose of this interface is to enable the user to set the external PCM callback interface and do not want the SDK to play a sound.
2.4.10 Setting RTMP/RTSP playback parameters
InitCommonSDKParam() :
2.4.10.1 Optional interface Settings before playback
- NT_SP_SetBuffer: Sets the size of the video playback buffer, in milliseconds.
- NT_SP_SetRTSPTcpMode: Sets the RTSP TCP mode. 1 is TCP and 0 is UDP. This interface is valid only for RTSP.
- NT_SP_SetRtspTimeout: sets the RTSP timeout period. The timeout unit is second and must be greater than 0.
- NT_SP_SetRtspAutoSwitchTcpUdp: For RTSP, some may support RTP over UDP and some may support RTP over TCP. If udp cannot be played, SDK will automatically try TCP. If TCP cannot be played, SDK will automatically try UDP. Is_auto_switch_tcp_udp: If set to 1, THE SDK will try to switch playback between TCP and UDP. If set to 0, the SDK will not try to switch playback.
- NT_SP_SetFastStartup: enable in seconds. 1 is enabled in seconds and 0 is not enabled in seconds. This interface is used when the RTMP server caches the GOP.
- NT_SP_SetLowLatencyMode: sets the low-delay playback mode. The default mode is normal. Mode: 1 indicates the low-delay mode, and 0 indicates the normal mode.
- NT_SP_SetReportDownloadSpeed: sets the download speed to be reported. The download speed is not reported by default.
* is_report: switch for reporting, 1: table reporting 0: no reporting Other values are invalid.
* report_interval: reporting interval (reporting frequency), expressed in seconds. The minimum value is once every second. If the value is less than 1 and the report function is set, the call fails
* Note: If set to report, set SetEventCallBack and handle the event in the callback function.
* The reported event is NT_SP_E_EVENT_ID_DOWNLOAD_SPEED
- NT_SP_GetDownloadSpeed: proactively obtains the download speed. Speed: returns the download speed, expressed in Byte/s.
- NT_SP_SetParam: universal interface, set parameters, most problems, these interfaces can solve;
- NT_SP_GetParam: universal interface, get parameters, most problems, these interfaces can solve;
2.4.10.2 Interfaces that can be called in real time before and after playback
- NT_SP_SetMute: Mute or unmute in real time during playing. It can be called before playing or in real time during playing.
- NT_SP_SetAudioVolume: different from the real-time mute interface, this interface can control the volume with finer granularity. The default range is 0,100, where 0 is mute and 100 is maximum volume. The default value is 100.
- NT_SP_SetOnlyDecodeVideoKeyFrame: window play more scenarios, some Windows may only need to play the key frames, such as demand has a similar scene, can use this interface;
- NT_SP_SetRotation: sets the video View rotation and rotates clockwise. Degress: sets 0, 90, 180, and 270 degrees, and other values are invalid. Note: Other angles except 0 degrees consume more CPU.
- NT_SP_SetFlipVertical: Set the video View to invert up and down (vertical invert);
- NT_SP_SetFlipHorizontal: Set video View horizontal reversal;
- NT_SP_SetRenderScaleMode: Set the filling mode of the video picture, such as filling the whole drawing window, equal proportion filling the drawing window, if not set, the default filling the whole drawing window;
2.4.11 Start Playing
NT_SP_StartPlay
Start playing RTMP or RTSP stream data.
2.4.12 RTMP/RTSP Pull video recording
- NT_SP_SetRecorderDirectory: Sets the recording directory
- NT_SP_SetRecorderFileMaxSize: Sets the maximum size of a single file
- NT_SP_SetRecorderFileNameRuler: Sets the rule for generating video file names
- NT_SP_SetRecorderCallBack: Sets the recording callback interface
- NT_SP_SetRecorderAudioTranscodeAAC: set up the video turn AAC audio coding switch, AAC is general, the SDK to increase other audio coding (such as speex pcmu, pcma, etc.) turn the function of AAC
- NT_SP_SetRecorderVideo: Sets whether or not to record a video. By default, if the video source has a video, it will record it. If the video source does not have a video, it will not record it
- NT_SP_SetRecorderAudio: Sets whether or not to record audio. By default, if the video source has audio, it will record, if it does not have audio, it will not record, but some scenarios may not want to record audio, only want to record video, so add a switch
- NT_SP_StartRecorder: Start recording
- NT_SP_StopRecorder: Stops recording
2.4.13 Real-time Snapshot
NT_SP_CaptureImage
The player intercepts the current image in real time and saves the image in PNG format to the local PC.
String name = capture_image_path_ + "\ \" + DateTime.Now.ToString("hh-mm-ss") + ".png";
byte[] buffer1 = Encoding.Default.GetBytes(name);
byte[] buffer2 = Encoding.Convert(Encoding.Default, Encoding.UTF8, buffer1, 0, buffer1.Length);
byte[] buffer3 = new byte[buffer2.Length + 1];
buffer3[buffer2.Length] = 0;
Array.Copy(buffer2, buffer3, buffer2.Length);
IntPtr file_name_ptr = Marshal.AllocHGlobal(buffer3.Length);
Marshal.Copy(buffer3, 0, file_name_ptr, buffer3.Length);
capture_image_call_back_ = new SP_SDKCaptureImageCallBack(SDKCaptureImageCallBack);
UInt32 ret = NTSmartPlayerSDK.NT_SP_CaptureImage(player_handle_, file_name_ptr, IntPtr.Zero, capture_image_call_back_);
Marshal.FreeHGlobal(file_name_ptr);
if (NT.NTBaseCodeDefine.NT_ERC_OK == ret)
{
// The request for sending the screenshot succeeded
}
else if ((UInt32)NT.NTSmartPlayerDefine.SP_E_ERROR_CODE.NT_ERC_SP_TOO_MANY_CAPTURE_IMAGE_REQUESTS == ret)
{
// Notify the user of delay
MessageBox.Show("Too many capture image requests!");
}
else
{
// Other failures
}
Copy the code
2.4.14 Quickly Switching urls
NT_SP_SwitchURL
Quick URL switch, used to switch playing urls in real time without destructing the entire Player instance.
2.4.15 User Data Callback
NT_SP_SetUserDataCallBack
Set the user data callback to receive the user data sent by the extension SEI module. This interface does not need to be called unless we extend SEI to send DK.
2.4.16 SEI Data Callback
NT_SP_SetSEIDataCallBack
Set video SEI data callback for receiving SEI data callback. This interface does not need to be called if the STREAM data does not exist or is not going to process SEI data.
2.4.17 Stop Playback
NT_SP_StopPlay
Stop playing RTMP or RTSP stream data.
2.4.18 Disable the playback instance
NT_SP_Close
After calling the Close interface, the Player Handler is null.
if( player_handle_ ! = IntPtr.Zero) { NTSmartPlayerSDK.NT_SP_Close(player_handle_); player_handle_ = IntPtr.Zero; }Copy the code
2.4.19 Uninit
NT_SP_UnInit
UnInit() is the last interface called by the SDK. In a multi-instance environment, you only need to call it once.