### Start Audio Capture Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Begins capturing audio from the selected device with specified encoding parameters. This function requires the audio capture device to be opened first and a callback function to be registered. ```cpp // 开始音频采集(自定义格式) libEasyPlayer_StartAudioCaptureByParam( playerHandle, RTSP_AUDIO_CODEC_G711A, // 编码格式 320, // 帧大小(G711为160/320,AAC为1024/2048) 8000, // 采样率 16, // 位深度 1, // 通道数 AudioCaptureCallback, NULL ); ``` -------------------------------- ### Local Recording Functionality Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Starts local video recording with options for splitting by file size or duration, and enabling pre-recording. Pre-recording duration is determined by `queueSize` during `OpenStream`. Recording completion or failure is notified via callback. ```cpp // 开始录像(按文件大小分割,100MB) int ret = libEasyPlayer_StartRecording( playerHandle, channelId, "D:\\recordings", // 录像保存目录 "camera1", // 文件名前缀 100, // 文件大小(MB),0表示使用时长 0, // 录像时长(秒),filesize>0时无效 0 // 0=不预录, 1=预录(包含之前缓存的数据) ); // 开始录像(按时长分割,每5分钟一个文件) ret = libEasyPlayer_StartRecording( playerHandle, channelId, "D:\\recordings", "camera1", 0, // 文件大小设为0 300, // 300秒 = 5分钟 1 // 启用预录 ); // 录像完成后会通过回调通知 // callbackType == EASY_TYPE_RECORDING // mediaType == MEDIA_TYPE_VIDEO 表示成功 // mediaType == MEDIA_TYPE_EVENT 表示失败 // pbuf 包含录像文件名 // 停止录像 libEasyPlayer_StopRecording(playerHandle, channelId); ``` -------------------------------- ### Get Audio Capture Device List Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Retrieves a list of available audio capture devices connected to the system. This is the first step before opening a specific device for audio capture. ```cpp // 获取音频采集设备列表 int deviceNum = 0; LIVE_AUDIO_CAPTURE_DEVICE_INFO *pDeviceInfo = NULL; libEasyPlayer_GetAudioCaptureDeviceList(playerHandle, &deviceNum, &pDeviceInfo); for (int i = 0; i < deviceNum; i++) { printf("采集设备 %d: %s\n", i, pDeviceInfo[i].description); } ``` -------------------------------- ### Start Instant Replay Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Initiates an instant replay of cached video data. Note that instant replay and manual recording are mutually exclusive. The replay duration is determined by the queue size set in OpenStream. ```cpp // 注意:即时回放与手动录像互斥,不能同时使用 // 开始即时回放 int ret = libEasyPlayer_InstantReplay_Start(playerHandle, channelId); if (ret == 0) { printf("即时回放已开始\n"); } ``` -------------------------------- ### Open Stream with Callbacks Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Shows how to open various streaming sources using `libEasyPlayer_OpenStream`. It includes a detailed callback function `PlayerCallBack` that handles different event types such as connection status, codec data, snapshots, and recording. Examples cover RTSP, RTMP, HLS, and local file playback, demonstrating parameter usage for authentication, media types, buffering, and reconnection. ```cpp // 回调函数定义 int CALLBACK PlayerCallBack(EASY_CALLBACK_TYPE_ENUM callbackType, int channelId, void *userPtr, int mediaType, char *pbuf, LIVE_FRAME_INFO *frameInfo) { switch (callbackType) { case EASY_TYPE_CONNECTING: printf("通道 %d 正在连接...\n", channelId); break; case EASY_TYPE_CONNECTED: printf("通道 %d 连接成功\n", channelId); break; case EASY_TYPE_DISCONNECT: printf("通道 %d 连接断开\n", channelId); break; case EASY_TYPE_RECONNECT: printf("通道 %d 正在重连...\n", channelId); break; case EASY_TYPE_CODEC_DATA: // 编码数据回调,可用于录像或分析 if (mediaType == MEDIA_TYPE_VIDEO) { printf("视频帧: %dx%d, 大小: %d\n", frameInfo->width, frameInfo->height, frameInfo->length); } break; case EASY_TYPE_SNAPSHOT: if (mediaType == MEDIA_TYPE_VIDEO) printf("截图成功: %s\n", pbuf); else printf("截图失败\n"); break; case EASY_TYPE_RECORDING: printf("录像%s: %s\n", mediaType == MEDIA_TYPE_VIDEO ? "成功" : "失败", pbuf); break; } return 0; } // 打开RTSP流 LIVE_CHANNEL_SOURCE_TYPE_ENUM sourceType = LIVE_CHANNEL_SOURCE_TYPE_RTSP; const char* url = "rtsp://admin:admin123@192.168.1.100:554/stream1"; int rtpOverTcp = 1; // 1=TCP, 0=UDP int queueSize = 1024 * 1024 * 2; // 2MB缓冲队列 int multiplex = 0; // 0=不复用, 1=复用源 int channelId = libEasyPlayer_OpenStream( playerHandle, sourceType, url, rtpOverTcp, "admin", // 用户名 "admin123", // 密码 MEDIA_TYPE_VIDEO | MEDIA_TYPE_AUDIO | MEDIA_TYPE_EVENT, PlayerCallBack, // 回调函数 NULL, // 用户指针 1, // 1=无限重连, 0=不重连, >1000=指定重连次数 0, // 心跳类型 queueSize, multiplex ); // 打开RTMP流 int rtmpChannel = libEasyPlayer_OpenStream( playerHandle, LIVE_CHANNEL_SOURCE_TYPE_RTMP, "rtmp://live.example.com/app/stream", 0, "", "", MEDIA_TYPE_VIDEO | MEDIA_TYPE_AUDIO, PlayerCallBack, NULL, 1, 0, 1024*1024*2, 0 ); // 打开HLS流(需要更大缓冲) int hlsChannel = libEasyPlayer_OpenStream( playerHandle, LIVE_CHANNEL_SOURCE_TYPE_HLS, "http://example.com/live/playlist.m3u8", 0, "", "", MEDIA_TYPE_VIDEO | MEDIA_TYPE_AUDIO, PlayerCallBack, NULL, 1, 0, 1024*1024*5, 0 // 5MB缓冲 ); // 打开本地文件 int fileChannel = libEasyPlayer_OpenStream( playerHandle, LIVE_CHANNEL_SOURCE_TYPE_FILE, "file://D:\\videos\\test.mp4", 0, "", "", MEDIA_TYPE_VIDEO | MEDIA_TYPE_AUDIO, PlayerCallBack, NULL, 0, 0, 1024*1024*2, 0 ); ``` -------------------------------- ### Push External Data to EasyPlayerPro Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Use this pattern to manually inject encoded video and audio frames into the player. Ensure h264Data contains complete NAL units with start codes. ```cpp // 打开外部数据输入通道 int channelId = libEasyPlayer_OpenStream( playerHandle, LIVE_CHANNEL_SOURCE_TYPE_ENCODE_DATA, // 外部编码数据模式 "", // URL为空 0, "", "", MEDIA_TYPE_VIDEO | MEDIA_TYPE_AUDIO, NULL, // 可以不设置回调 NULL, 0, // 不重连 0, 1024 * 1024 * 2, 0 ); // 开始播放 libEasyPlayer_StartPlayStream(playerHandle, channelId, hWnd, RENDER_FORMAT_YV12, 0); libEasyPlayer_SetPlayFrameCache(playerHandle, channelId, 3); // 推送视频帧数据 LIVE_FRAME_INFO frameInfo; memset(&frameInfo, 0, sizeof(LIVE_FRAME_INFO)); frameInfo.codec = RTSP_VIDEO_CODEC_H264; // 0x1C frameInfo.width = 1920; frameInfo.height = 1080; frameInfo.length = h264FrameSize; frameInfo.type = LIVE_FRAME_TYPE_I; // I帧=0x01, P帧=0x02, B帧=0x03 // h264Data 应该包含完整的 NAL 单元(带起始码) libEasyPlayer_PutFrameData( playerHandle, channelId, MEDIA_TYPE_VIDEO, &frameInfo, h264Data ); // 推送音频帧数据 LIVE_FRAME_INFO audioInfo; memset(&audioInfo, 0, sizeof(LIVE_FRAME_INFO)); audioInfo.codec = RTSP_AUDIO_CODEC_AAC; audioInfo.sample_rate = 44100; audioInfo.channels = 2; audioInfo.length = aacFrameSize; libEasyPlayer_PutFrameData( playerHandle, channelId, MEDIA_TYPE_AUDIO, &audioInfo, aacData ); // 重置帧队列(从下一个关键帧开始播放) libEasyPlayer_ResetFrameQueue(playerHandle, channelId); ``` -------------------------------- ### Open Audio Capture Device Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Opens a specified audio capture device and retrieves information about the supported audio wave formats. This function must be called before starting audio capture. ```cpp // 打开采集设备并获取支持的格式 int waveFormatNum = 0; LIVE_AUDIO_WAVE_FORMAT_INFO *pWaveFormat = NULL; libEasyPlayer_OpenAudioCaptureDevice( playerHandle, 0, // 设备索引 &waveFormatNum, &pWaveFormat ); ``` -------------------------------- ### Start Video Playback and Rendering Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Initiates video decoding and rendering. Supports D3D and GDI rendering formats. D3D offers advanced features like video flipping. Ensure the correct window handle and rendering format are specified. ```cpp // 渲染格式枚举 // RENDER_FORMAT_YV12 - D3D YV12格式(推荐,性能最佳) // RENDER_FORMAT_YUY2 - D3D YUY2格式 // RENDER_FORMAT_RGB565 - D3D RGB565格式 // RENDER_FORMAT_X8R8G8B8 - D3D 32位色 // RENDER_FORMAT_RGB24_GDI - GDI RGB24格式(兼容性最好) // RENDER_FORMAT_RGB32_GDI - GDI RGB32格式 HWND hWnd = GetDlgItem(IDC_VIDEO_WINDOW)->GetSafeHwnd(); // 使用GDI渲染(兼容性好) int ret = libEasyPlayer_StartPlayStream( playerHandle, channelId, hWnd, RENDER_FORMAT_RGB24_GDI, 0 // 0=软解, 1=硬解 ); // 使用D3D渲染(性能好,支持翻转) ret = libEasyPlayer_StartPlayStream( playerHandle, channelId, hWnd, RENDER_FORMAT_YV12, 0 ); if (ret == 0) { // 设置播放缓存帧数(1-10,越小延迟越低) libEasyPlayer_SetPlayFrameCache(playerHandle, channelId, 3); // 设置按比例显示 libEasyPlayer_SetScaleDisplay(playerHandle, channelId, 1, RGB(0x26, 0x26, 0x26)); // 显示OSD统计信息 libEasyPlayer_ShowStatisticalInfo(playerHandle, channelId, 1); } // 停止播放 libEasyPlayer_StopPlayStream(playerHandle, channelId); // 关闭流 libEasyPlayer_CloseStream(playerHandle, channelId); ``` -------------------------------- ### Get Stream Media Info Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Retrieves detailed media information about the current playback stream, including video and audio codec, resolution, frame rate, and bitrate. It also provides SPS/PPS lengths for H.264/H.265 streams. ```cpp LIVE_MEDIA_INFO_T mediaInfo; memset(&mediaInfo, 0, sizeof(LIVE_MEDIA_INFO_T)); int ret = libEasyPlayer_GetStreamInfo(playerHandle, channelId, &mediaInfo); if (ret == 0) { // 视频信息 printf("视频编码: 0x%X\n", mediaInfo.videoCodec); // 0x1C=H264, 0xAE=H265, 0x08=MJPEG, 0x0D=MPEG4 printf("分辨率: %dx%d\n", mediaInfo.videoWidth, mediaInfo.videoHeight); printf("帧率: %d fps\n", mediaInfo.videoFps); printf("码率: %.2f Kbps\n", mediaInfo.videoBitrate); // 音频信息 printf("音频编码: 0x%X\n", mediaInfo.audioCodec); // 0x15002=AAC, 0x10006=G711U, 0x10007=G711A, 0x1100B=G726 printf("采样率: %d Hz\n", mediaInfo.audioSampleRate); printf("通道数: %d\n", mediaInfo.audioChannel); printf("位深度: %d bit\n", mediaInfo.audioBitsPerSample); // SPS/PPS信息(用于H264/H265) if (mediaInfo.spsLength > 0) { printf("SPS长度: %d\n", mediaInfo.spsLength); } if (mediaInfo.ppsLength > 0) { printf("PPS长度: %d\n", mediaInfo.ppsLength); } } ``` -------------------------------- ### Electronic Zoom Functionality Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Enables region-based electronic zoom for detailed observation within the video feed. Allows setting start and end points for the zoom area, applying the zoom, and resetting the view. Use percentage coordinates relative to the window. ```cpp // 设置放大起始点(百分比坐标,相对于窗口) // 例如:从窗口30%宽度、20%高度位置开始 libEasyPlayer_SetElectronicZoomStartPoint( playerHandle, channelId, 0.3f, // X坐标百分比 0.2f, // Y坐标百分比 1 // 1=显示选择框, 0=不显示 ); // 设置放大结束点 // 例如:到窗口70%宽度、80%高度位置 libEasyPlayer_SetElectronicZoomEndPoint( playerHandle, channelId, 0.7f, 0.8f ); // 执行放大 libEasyPlayer_SetElectronicZoom(playerHandle, channelId, 1); // 1=放大 // 取消放大,恢复原始显示 libEasyPlayer_SetElectronicZoom(playerHandle, channelId, 0); // 0=不放大 // 重置放大区域 libEasyPlayer_ResetElectronicZoom(playerHandle, channelId); ``` -------------------------------- ### Initialize EasyPlayerPro SDK Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Demonstrates two methods for initializing the EasyPlayerPro SDK: handle-based creation (recommended) and global initialization. The handle-based mode allows for flexible multi-instance management, while the global mode uses a NULL handle for subsequent calls. Both methods specify the maximum number of supported channels. ```cpp #include "lib EasyPlayer/lib EasyPlayerAPI.h" #pragma comment(lib, "lib EasyPlayer/lib EasyPlayer.lib") // 方式一:句柄创建模式(推荐) PLAYER_HANDLE playerHandle = NULL; int ret = libEasyPlayer_Create(&playerHandle, 128); // 支持最多128通道 if (ret == 0) { // 播放器创建成功,可以开始使用 // ... 播放操作 ... // 释放资源 libEasyPlayer_Release(&playerHandle); } // 方式二:全局初始化模式 int ret = libEasyPlayer_Initialize(64); // 全局支持64通道 if (ret == 0) { // 初始化成功,后续调用 handle 参数传 NULL // ... 播放操作 ... // 反初始化 libEasyPlayer_Deinitialize(); } ``` -------------------------------- ### Configure EasyPlayerPro via XML Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Define player settings and channel information using an XML configuration file for automatic startup and playback. ```xml 4 1 0 0 100 300 1 ``` -------------------------------- ### Snapshot and Capture Functionality Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Supports both synchronous and asynchronous snapshot modes, saving to BMP or JPG. Asynchronous mode is recommended to avoid blocking the main thread, with results delivered via callback. Synchronous mode returns immediately upon completion. ```cpp // 异步截图到文件(推荐) int ret = libEasyPlayer_SnapshotToFile( playerHandle, channelId, 1, // 0=BMP, 1=JPG "D:\\snapshots\\cap1.jpg", 0, // 0=异步, 1=同步 0 // 0=不使用队列, 1=使用队列 ); // 结果通过 EASY_TYPE_SNAPSHOT 回调通知 // 同步截图到文件 ret = libEasyPlayer_SnapshotToFile( playerHandle, channelId, 0, // BMP格式 "D:\\snapshots\\cap2.bmp", 1, // 同步模式 0 ); if (ret == 0) { printf("截图成功\n"); } // 截图到内存 unsigned char imageData[1920 * 1080 * 3]; // RGB数据缓冲 int imageSize = 0; int width = 0, height = 0; ret = libEasyPlayer_SnapshotToMemory( playerHandle, channelId, 0, // 0=RGB, 1=JPG imageData, &imageSize, &width, &height ); if (ret == 0) { printf("截图到内存成功: %dx%d, 大小: %d\n", width, height, imageSize); // imageData 包含 RGB 或 JPG 数据 } ``` -------------------------------- ### Save Instant Replay Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Saves the content of the current instant replay to a specified file path. Ensure the directory exists and has write permissions. ```cpp // 保存即时回放内容到文件 ret = libEasyPlayer_InstantReplay_Save( playerHandle, channelId, "D:\\recordings\\instant_replay.mp4" ); ``` -------------------------------- ### Control Instant Replay Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Provides functions to pause, resume, and stop the instant replay. It also allows retrieving the current playback progress. ```cpp // 暂停回放 libEasyPlayer_InstantReplay_Pause(playerHandle, channelId); // 恢复回放 libEasyPlayer_InstantReplay_Resume(playerHandle, channelId); // 获取回放进度 int currentFrame = 0, totalFrames = 0; libEasyPlayer_InstantReplay_GetFrameNum( playerHandle, channelId, ¤tFrame, &totalFrames ); printf("回放进度: %d / %d\n", currentFrame, totalFrames); ``` -------------------------------- ### Set Scale Display Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Configures how the video is displayed within its container. Options include stretching to fill the container or maintaining the original aspect ratio with a specified border color. ```cpp // 设置按比例显示 // 0=铺满窗口, 1=按原始比例显示 libEasyPlayer_SetScaleDisplay( playerHandle, channelId, 1, // 按比例显示 RGB(0x26, 0x26, 0x26) // 黑边颜色 ); ``` -------------------------------- ### Audio Capture Callback Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Defines a callback function that will be invoked when audio data is captured. The callback receives the encoded audio data and frame information. ```cpp // 音频采集回调 int CALLBACK AudioCaptureCallback(EASY_CALLBACK_TYPE_ENUM callbackType, int channelId, void *userPtr, int mediaType, char *pbuf, LIVE_FRAME_INFO *frameInfo) { if (callbackType == EASY_TYPE_CAPTURE_AUDIO_DATA) { // pbuf 包含编码后的音频数据 // frameInfo->length 为数据长度 printf("采集到音频数据: %d bytes\n", frameInfo->length); } return 0; } ``` -------------------------------- ### Set Render Rectangle Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Defines a custom rectangular area within the display window where the video will be rendered. This allows for precise positioning and sizing of the video output. ```cpp // 设置渲染区域(用于自定义显示位置) RECT renderRect = {0, 0, 640, 480}; libEasyPlayer_SetRenderRect(playerHandle, channelId, &renderRect); ``` -------------------------------- ### Set OSD Text Overlay Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Overlays custom text onto the video stream. This can be used for displaying information like camera names or status messages. ```cpp // 设置OSD叠加文字 libEasyPlayer_SetOverlayText(playerHandle, channelId, "摄像头01 - 大厅入口"); ``` -------------------------------- ### Show Statistical Info Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Toggles the display of statistical information, such as frame rate and bitrate, directly on the video output. ```cpp // 显示/隐藏统计信息(帧率、码率等) libEasyPlayer_ShowStatisticalInfo(playerHandle, channelId, 1); // 1=显示 ``` -------------------------------- ### Audio Playback Control Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Manages audio playback, volume, and device switching. Only one channel's audio can play at a time; switching channels stops the previous one. Ensure correct player handle and channel ID are used. ```cpp // 开始播放音频 int ret = libEasyPlayer_StartPlaySound(playerHandle, channelId); if (ret == 0) { printf("音频播放已开启\n"); } // 检查音频播放状态 ret = libEasyPlayer_SoundPlaying(playerHandle, channelId); if (ret == 0) { printf("通道 %d 正在播放音频\n", channelId); } // 设置音量(0-100) libEasyPlayer_SetAudioVolume(playerHandle, 80); // 获取当前音量 int volume = libEasyPlayer_GetAudioVolume(playerHandle); printf("当前音量: %d\n", volume); // 获取音频输出设备列表 MIXER_DEVICE_INFO_T *deviceList = NULL; int deviceNum = 0; libEasyPlayer_GetAudioOutputDeviceList(playerHandle, &deviceList, &deviceNum); for (int i = 0; i < deviceNum; i++) { printf("设备 %d: %s\n", deviceList[i].id, deviceList[i].name); } // 切换音频输出设备 libEasyPlayer_SetAudioOutputDeviceId(playerHandle, 1); // 或通过设备名称切换 libEasyPlayer_SetAudioOutputDeviceName(playerHandle, "扬声器 (Realtek Audio)"); // 停止音频播放 libEasyPlayer_StopPlaySound(playerHandle); ``` -------------------------------- ### Set Decode Type Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Configures the decoder to process only keyframes. This reduces CPU usage but results in non-continuous video playback. ```cpp // 设置只解码关键帧(降低CPU占用,但画面不连贯) libEasyPlayer_SetDecodeType(playerHandle, channelId, 1); // 1=只解关键帧 ``` -------------------------------- ### Stop Instant Replay Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Stops the ongoing instant replay operation. ```cpp // 停止即时回放 libEasyPlayer_InstantReplay_Stop(playerHandle, channelId); ``` -------------------------------- ### Set Video Flip Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Applies a vertical flip to the video stream. This feature is only supported in D3D rendering mode. ```cpp // 视频翻转(仅D3D渲染模式支持) libEasyPlayer_SetVideoFlip(playerHandle, channelId, 1); // 1=翻转, 0=正常 ``` -------------------------------- ### Close Audio Capture Device Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Releases the audio capture device, freeing up system resources. This should be called after stopping audio capture. ```cpp // 关闭采集设备 libEasyPlayer_CloseAudioCaptureDevice(playerHandle); ``` -------------------------------- ### Clear OSD Text Overlay Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Removes any previously set text overlays from the video stream. ```cpp // 清除OSD叠加 libEasyPlayer_ClearOverlayText(playerHandle, channelId); ``` -------------------------------- ### Stop Audio Capture Source: https://context7.com/easydarwin/easyplayerpro/llms.txt Stops the ongoing audio capture process. ```cpp // 停止音频采集 libEasyPlayer_StopAudioCapture(playerHandle); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.