@tencent-rtc/mcp 1.2.7 → 1.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/resource/doc/native_live/android/V2TXLiveCode_api_android.md +312 -0
- package/resource/doc/native_live/android/V2TXLiveDef_api_android.md +430 -0
- package/resource/doc/native_live/android/V2TXLivePlayerObserver_api_android.md +679 -0
- package/resource/doc/native_live/android/V2TXLivePlayer_api_android.md +671 -0
- package/resource/doc/native_live/android/V2TXLivePremier_api_android.md +271 -0
- package/resource/doc/native_live/android/V2TXLivePusherObserver_api_android.md +849 -0
- package/resource/doc/native_live/android/V2TXLivePusher_api_android.md +1046 -0
- package/resource/doc/native_live/flutter/V2TXLiveCode_api_flutter.md +460 -0
- package/resource/doc/native_live/flutter/V2TXLiveDef_api_flutter.md +558 -0
- package/resource/doc/native_live/flutter/V2TXLivePlayerObserver_api_flutter.md +865 -0
- package/resource/doc/native_live/flutter/V2TXLivePlayer_api_flutter.md +657 -0
- package/resource/doc/native_live/flutter/V2TXLivePremier_api_flutter.md +437 -0
- package/resource/doc/native_live/flutter/V2TXLivePusherObserver_api_flutter.md +335 -0
- package/resource/doc/native_live/flutter/V2TXLivePusher_api_flutter.md +748 -0
- package/resource/doc/native_live/iOS/V2TXLiveCode_api_iOS.md +327 -0
- package/resource/doc/native_live/iOS/V2TXLiveDef_api_iOS.md +507 -0
- package/resource/doc/native_live/iOS/V2TXLivePlayerObserver_api_iOS.md +507 -0
- package/resource/doc/native_live/iOS/V2TXLivePlayer_api_iOS.md +659 -0
- package/resource/doc/native_live/iOS/V2TXLivePremier_api_iOS.md +284 -0
- package/resource/doc/native_live/iOS/V2TXLivePusherObserver_api_iOS.md +814 -0
- package/resource/doc/native_live/iOS/V2TXLivePusher_api_iOS.md +1000 -0
- package/tools/common/get-faq.js +1 -1
- package/tools/common/get-faq.js.map +1 -1
- package/tools/definitions/get_native_live_api_def.js +23 -0
- package/tools/definitions/get_native_live_api_def.js.map +1 -0
- package/tools/index.js +4 -0
- package/tools/index.js.map +1 -1
- package/tools/native_live/get-native-live-api.js +31 -0
- package/tools/native_live/get-native-live-api.js.map +1 -0
- package/utils/report-cls-client.js +1 -1
- package/utils/report-es-client.js +1 -1
|
@@ -0,0 +1,748 @@
|
|
|
1
|
+
# Tencent Cloud Live Streaming SDK V2TXLivePusher Streaming Interface Documentation
|
|
2
|
+
|
|
3
|
+
## Feature Overview
|
|
4
|
+
|
|
5
|
+
`V2TXLivePusher` is the primary streaming interface in the Tencent Cloud TRTC Live Streaming SDK. It handles encoding of local audio and video and pushes the stream to a specified streaming URL, compatible with any streaming server.
|
|
6
|
+
|
|
7
|
+
### 🎯 Core Features
|
|
8
|
+
- ✅ **Multiple Capture Sources**: Camera, microphone, screen, image, custom capture
|
|
9
|
+
- ✅ **Video Controls**: Rotation, fill mode, mirroring, watermark
|
|
10
|
+
- ✅ **Streaming Controls**: Start/stop, pause/resume, separate audio/video
|
|
11
|
+
- ✅ **Effects Processing**: Beauty, filters, stickers, audio effects
|
|
12
|
+
- ✅ **Cloud Stream Mixing**: Multi-channel audio/video stream mix transcoding
|
|
13
|
+
- ✅ **Local Recording**: Record local audio/video streams
|
|
14
|
+
- ✅ **Custom Capture**: Support for external devices and custom formats
|
|
15
|
+
|
|
16
|
+
### 🔧 Technical Highlights
|
|
17
|
+
- **Low Latency**: Optimized encoding and adaptive network strategies
|
|
18
|
+
- **High Compatibility**: Supports various video encoding formats and resolutions
|
|
19
|
+
- **Easy Integration**: Simple API design with robust callback support
|
|
20
|
+
- **High Performance**: Accelerated hardware encoding and efficient capture pipeline
|
|
21
|
+
|
|
22
|
+
### Creating a Pusher Instance
|
|
23
|
+
```dart
|
|
24
|
+
// Create a streaming instance using the RTC protocol. startPush requires an RTC protocol URL.
|
|
25
|
+
V2TXLivePusher pusher = await V2TXLivePusher.create(V2TXLiveMode.V2TXLiveModeRTC);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
**Protocol Selection Guidelines**:
|
|
29
|
+
- **RTMP Protocol**: Best for CDN live distribution; latency is typically 2–3 seconds.
|
|
30
|
+
- **RTC Protocol**: Ideal for real-time interactive scenarios; latency is typically under 400ms.
|
|
31
|
+
|
|
32
|
+
## File Information
|
|
33
|
+
|
|
34
|
+
- **File Path**: `v2_tx_live_pusher.dart`
|
|
35
|
+
- **Dependencies**:
|
|
36
|
+
- `v2_tx_live_code.dart` – Error code definitions
|
|
37
|
+
- `v2_tx_live_def.dart` – Type definitions
|
|
38
|
+
- `v2_tx_live_pusher_observer.dart` – Observer callback interface
|
|
39
|
+
- `tx_audio_effect_manager.dart` – Audio effect management
|
|
40
|
+
- `tx_device_manager.dart` – Device management
|
|
41
|
+
|
|
42
|
+
## Class Definition
|
|
43
|
+
|
|
44
|
+
```dart
|
|
45
|
+
abstract class V2TXLivePusher {
|
|
46
|
+
V2TXLivePusher() {}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Static Methods
|
|
51
|
+
|
|
52
|
+
### create
|
|
53
|
+
**Purpose**: Create a pusher instance
|
|
54
|
+
```dart
|
|
55
|
+
static Future<V2TXLivePusher> create(V2TXLiveMode liveMode) async
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**Parameters**:
|
|
59
|
+
- `liveMode`: Streaming mode [V2TXLiveMode]
|
|
60
|
+
|
|
61
|
+
**Returns**:
|
|
62
|
+
- `Future<V2TXLivePusher>`: The created pusher instance
|
|
63
|
+
|
|
64
|
+
**Usage Example**:
|
|
65
|
+
```dart
|
|
66
|
+
V2TXLivePusher pusher = await V2TXLivePusher.create(V2TXLiveMode.V2TXLiveModeRTC);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Observer Management
|
|
70
|
+
|
|
71
|
+
### addListener
|
|
72
|
+
**Purpose**: Register a pusher callback observer
|
|
73
|
+
```dart
|
|
74
|
+
void addListener(V2TXLivePusherObserver observer)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Parameters**:
|
|
78
|
+
- `observer`: Observer object implementing the `V2TXLivePusherObserver` protocol
|
|
79
|
+
|
|
80
|
+
**When to Call**: Immediately after initializing the pusher
|
|
81
|
+
|
|
82
|
+
**Description**: Use callbacks to monitor pusher status, volume changes, statistics, warnings, and errors.
|
|
83
|
+
|
|
84
|
+
**Example**:
|
|
85
|
+
```dart
|
|
86
|
+
pusher.addListener(V2TXLivePusherObserver(
|
|
87
|
+
onPushStatusUpdate: (status, msg, extraInfo) {
|
|
88
|
+
// Handle streaming status changes
|
|
89
|
+
},
|
|
90
|
+
onStatisticsUpdate: (statistics) {
|
|
91
|
+
// Handle statistics
|
|
92
|
+
},
|
|
93
|
+
onError: (code, msg, extraInfo) {
|
|
94
|
+
// Handle error information
|
|
95
|
+
}
|
|
96
|
+
));
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### removeListener
|
|
100
|
+
**Purpose**: Unregister a pusher callback observer
|
|
101
|
+
```dart
|
|
102
|
+
void removeListener(V2TXLivePusherObserver observer)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
**Parameters**:
|
|
106
|
+
- `observer`: Observer object [V2TXLivePusherObserver]
|
|
107
|
+
|
|
108
|
+
### destroy
|
|
109
|
+
**Purpose**: Destroy the pusher instance and release resources
|
|
110
|
+
```dart
|
|
111
|
+
void destroy()
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Video Rendering Controls
|
|
115
|
+
|
|
116
|
+
### setRenderViewID
|
|
117
|
+
**Purpose**: Set the view ID for local camera preview
|
|
118
|
+
```dart
|
|
119
|
+
Future<V2TXLiveCode> setRenderViewID(int viewID)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**Parameters**:
|
|
123
|
+
- `viewID`: ID of the view for local camera preview
|
|
124
|
+
|
|
125
|
+
**Returns**: `V2TXLiveCode`
|
|
126
|
+
- `V2TXLIVE_OK`: Success
|
|
127
|
+
|
|
128
|
+
**When to Call**: Set the preview view before starting the stream
|
|
129
|
+
|
|
130
|
+
**Description**: The video captured by the local camera, after applying beauty, face shape adjustment, filters, and other effects, is displayed in the specified view.
|
|
131
|
+
|
|
132
|
+
**Example**:
|
|
133
|
+
```dart
|
|
134
|
+
await pusher.setRenderViewID(yourTextureViewID);
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### setRenderMirror
|
|
138
|
+
**Purpose**: Set camera mirroring mode for preview
|
|
139
|
+
```dart
|
|
140
|
+
Future<V2TXLiveCode> setRenderMirror(V2TXLiveMirrorType mirrorType)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**Parameters**:
|
|
144
|
+
- `mirrorType`: Mirroring mode [V2TXLiveMirrorType]
|
|
145
|
+
- `V2TXLiveMirrorType.v2TXLiveMirrorTypeAuto`: Default; front camera mirrored, rear camera not mirrored
|
|
146
|
+
- `V2TXLiveMirrorType.v2TXLiveMirrorTypeEnable`: Both front and rear cameras mirrored
|
|
147
|
+
- `V2TXLiveMirrorType.v2TXLiveMirrorTypeDisable`: Neither camera mirrored
|
|
148
|
+
|
|
149
|
+
### setEncoderMirror
|
|
150
|
+
**Purpose**: Set video encoding mirroring (affects only what the audience sees)
|
|
151
|
+
```dart
|
|
152
|
+
Future<V2TXLiveCode> setEncoderMirror(bool mirror)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**Parameters**:
|
|
156
|
+
- `mirror`: Whether to mirror the encoded video
|
|
157
|
+
- `false`: Default; audience sees non-mirrored video
|
|
158
|
+
- `true`: Audience sees mirrored video
|
|
159
|
+
|
|
160
|
+
### setRenderRotation
|
|
161
|
+
**Purpose**: Set rotation angle for local camera preview (local preview only)
|
|
162
|
+
```dart
|
|
163
|
+
Future<V2TXLiveCode> setRenderRotation(V2TXLiveRotation rotation)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
**Parameters**:
|
|
167
|
+
- `rotation`: Rotation angle [V2TXLiveRotation]
|
|
168
|
+
- `V2TXLiveRotation.v2TXLiveRotation0`: 0°, no rotation (default)
|
|
169
|
+
- `V2TXLiveRotation.v2TXLiveRotation90`: 90° clockwise
|
|
170
|
+
- `V2TXLiveRotation.v2TXLiveRotation180`: 180° clockwise
|
|
171
|
+
- `V2TXLiveRotation.v2TXLiveRotation270`: 270° clockwise
|
|
172
|
+
|
|
173
|
+
### setRenderFillMode
|
|
174
|
+
**Purpose**: Set video fill mode for preview
|
|
175
|
+
```dart
|
|
176
|
+
Future<V2TXLiveCode> setRenderFillMode(V2TXLiveFillMode mode)
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**Parameters**:
|
|
180
|
+
- `mode`: Video fill mode [V2TXLiveFillMode]
|
|
181
|
+
- `V2TXLiveFillMode.v2TXLiveFillModeFill`: Default; fills the screen, no black borders
|
|
182
|
+
- `V2TXLiveFillMode.v2TXLiveFillModeFit`: Fits the screen, preserves full image
|
|
183
|
+
|
|
184
|
+
## Capture Controls
|
|
185
|
+
|
|
186
|
+
### startCamera
|
|
187
|
+
**Purpose**: Start the local camera
|
|
188
|
+
```dart
|
|
189
|
+
Future<V2TXLiveCode> startCamera(bool frontCamera)
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
**Parameters**:
|
|
193
|
+
- `frontCamera`: Whether to use the front camera (default: true)
|
|
194
|
+
|
|
195
|
+
**Returns**: `V2TXLiveCode`
|
|
196
|
+
- `V2TXLIVE_OK`: Success
|
|
197
|
+
|
|
198
|
+
**Key Points**:
|
|
199
|
+
- **You must start at least one capture source before streaming; otherwise, streaming will fail.**
|
|
200
|
+
- Only one capture source (camera, virtual camera, or screen capture) can be active per pusher instance.
|
|
201
|
+
- To switch sources, stop the current source before starting a new one.
|
|
202
|
+
|
|
203
|
+
**When to Call**: Before starting the stream
|
|
204
|
+
|
|
205
|
+
**Example**:
|
|
206
|
+
```dart
|
|
207
|
+
// Start front camera
|
|
208
|
+
await pusher.startCamera(true);
|
|
209
|
+
// Start rear camera
|
|
210
|
+
await pusher.startCamera(false);
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### stopCamera
|
|
214
|
+
**Purpose**: Stop the local camera
|
|
215
|
+
```dart
|
|
216
|
+
Future<void> stopCamera()
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### startMicrophone
|
|
220
|
+
**Purpose**: Start microphone capture
|
|
221
|
+
```dart
|
|
222
|
+
Future<V2TXLiveCode> startMicrophone()
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
**Returns**: `V2TXLiveCode`
|
|
226
|
+
- `V2TXLIVE_OK`: Success
|
|
227
|
+
|
|
228
|
+
**Use Cases**:
|
|
229
|
+
- **Audio/video streaming**: Use with camera capture for audio
|
|
230
|
+
- **Audio-only streaming**: Use microphone alone
|
|
231
|
+
- **Screen sharing**: Use with screen capture for system and microphone audio
|
|
232
|
+
|
|
233
|
+
**Notes**:
|
|
234
|
+
- **Call this method before streaming to capture audio; otherwise, only video will be streamed.**
|
|
235
|
+
- For audio-only streaming, use microphone capture alone.
|
|
236
|
+
- Microphone capture can be enabled or disabled dynamically during streaming.
|
|
237
|
+
|
|
238
|
+
**When to Call**: Before starting the stream
|
|
239
|
+
|
|
240
|
+
**Example**:
|
|
241
|
+
```dart
|
|
242
|
+
// Start microphone capture
|
|
243
|
+
await pusher.startMicrophone();
|
|
244
|
+
// Stop microphone capture
|
|
245
|
+
await pusher.stopMicrophone();
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### stopMicrophone
|
|
249
|
+
**Purpose**: Stop microphone capture
|
|
250
|
+
```dart
|
|
251
|
+
Future<V2TXLiveCode> stopMicrophone()
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### startScreenCapture
|
|
255
|
+
**Purpose**: Start screen sharing
|
|
256
|
+
```dart
|
|
257
|
+
Future<V2TXLiveCode> startScreenCapture(String appGroup)
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**Parameters**:
|
|
261
|
+
- `appGroup`: iOS only; ignored on Android. The Application Group Identifier shared between the main app and broadcast process.
|
|
262
|
+
|
|
263
|
+
**Note**: Screen capture and camera capture are mutually exclusive.
|
|
264
|
+
|
|
265
|
+
### stopScreenCapture
|
|
266
|
+
**Purpose**: Stop screen sharing
|
|
267
|
+
```dart
|
|
268
|
+
Future<V2TXLiveCode> stopScreenCapture()
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## Streaming Controls
|
|
272
|
+
|
|
273
|
+
### startPush
|
|
274
|
+
**Purpose**: Start audio/video streaming
|
|
275
|
+
```dart
|
|
276
|
+
Future<V2TXLiveCode> startPush(String url)
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
**Parameters**:
|
|
280
|
+
- `url`: Streaming URL; supports any streaming server
|
|
281
|
+
|
|
282
|
+
**Returns**: `V2TXLiveCode`
|
|
283
|
+
- `V2TXLIVE_OK`: Success; connecting to streaming target
|
|
284
|
+
- `V2TXLIVE_ERROR_INVALID_PARAMETER`: Failed; invalid URL
|
|
285
|
+
- `V2TXLIVE_ERROR_INVALID_LICENSE`: Failed; invalid license or authentication
|
|
286
|
+
- `V2TXLIVE_ERROR_REFUSED`: Failed; RTC does not support pushing and pulling the same StreamId on the same device
|
|
287
|
+
|
|
288
|
+
**Key Points**:
|
|
289
|
+
- **Start at least one capture source before calling startPush(); otherwise, streaming will fail.**
|
|
290
|
+
- Supported sources: camera, microphone, screen, image, custom capture
|
|
291
|
+
- You can switch capture sources during streaming, but must stop the current source before starting a new one.
|
|
292
|
+
|
|
293
|
+
**When to Call**: After starting a capture source
|
|
294
|
+
|
|
295
|
+
**Example**:
|
|
296
|
+
```dart
|
|
297
|
+
V2TXLiveCode result = await pusher.startPush("rtmp://example.com/live/stream");
|
|
298
|
+
if (result == V2TXLiveCode.V2TXLIVE_OK) {
|
|
299
|
+
print('Streaming started successfully');
|
|
300
|
+
} else if (result == V2TXLiveCode.V2TXLIVE_ERROR_INVALID_PARAMETER) {
|
|
301
|
+
print('Invalid streaming address');
|
|
302
|
+
} else if (result == V2TXLiveCode.V2TXLIVE_ERROR_INVALID_LICENSE) {
|
|
303
|
+
print('Invalid Licence, please check your Licence');
|
|
304
|
+
} else if (result == V2TXLiveCode.V2TXLIVE_ERROR_REFUSED) {
|
|
305
|
+
print('Call refused');
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### stopPush
|
|
310
|
+
**Purpose**: Stop streaming
|
|
311
|
+
```dart
|
|
312
|
+
Future<V2TXLiveCode> stopPush()
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
### isPushing
|
|
316
|
+
**Purpose**: Check if streaming is active
|
|
317
|
+
```dart
|
|
318
|
+
Future<V2TXLiveCode> isPushing()
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
**Returns**:
|
|
322
|
+
- `1`: Streaming is active
|
|
323
|
+
- `0`: Streaming is stopped
|
|
324
|
+
|
|
325
|
+
## Audio/Video Controls
|
|
326
|
+
|
|
327
|
+
### pauseAudio
|
|
328
|
+
**Purpose**: Pause audio stream
|
|
329
|
+
```dart
|
|
330
|
+
Future<V2TXLiveCode> pauseAudio()
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### resumeAudio
|
|
334
|
+
**Purpose**: Resume audio stream
|
|
335
|
+
```dart
|
|
336
|
+
Future<V2TXLiveCode> resumeAudio()
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
### pauseVideo
|
|
340
|
+
**Purpose**: Pause video stream
|
|
341
|
+
```dart
|
|
342
|
+
Future<V2TXLiveCode> pauseVideo()
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### resumeVideo
|
|
346
|
+
**Purpose**: Resume video stream
|
|
347
|
+
```dart
|
|
348
|
+
Future<V2TXLiveCode> resumeVideo()
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
## Audio/Video Quality Settings
|
|
352
|
+
|
|
353
|
+
### setAudioQuality
|
|
354
|
+
**Purpose**: Set audio quality for streaming
|
|
355
|
+
```dart
|
|
356
|
+
Future<V2TXLiveCode> setAudioQuality(V2TXLiveAudioQuality quality)
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
**Parameters**:
|
|
360
|
+
- `quality`: Audio quality [V2TXLiveAudioQuality]
|
|
361
|
+
- `V2TXLiveAudioQuality.v2TXLiveAudioQualityDefault`: Default, general
|
|
362
|
+
- `V2TXLiveAudioQuality.v2TXLiveAudioQualitySpeech`: Speech
|
|
363
|
+
- `V2TXLiveAudioQuality.v2TXLiveAudioQualityMusic`: Music
|
|
364
|
+
|
|
365
|
+
**Returns**:
|
|
366
|
+
- `V2TXLIVE_OK`: Success
|
|
367
|
+
- `V2TXLIVE_ERROR_REFUSED`: Cannot change audio quality during streaming
|
|
368
|
+
|
|
369
|
+
### setVideoQuality
|
|
370
|
+
**Purpose**: Set video encoding parameters for streaming
|
|
371
|
+
```dart
|
|
372
|
+
Future<V2TXLiveCode> setVideoQuality(V2TXLiveVideoEncoderParam param)
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
**Parameters**:
|
|
376
|
+
- `param`: Video encoding parameters [V2TXLiveVideoEncoderParam]
|
|
377
|
+
|
|
378
|
+
## Audio Effects and Device Management
|
|
379
|
+
|
|
380
|
+
### getAudioEffectManager
|
|
381
|
+
**Purpose**: Access the audio effect manager
|
|
382
|
+
```dart
|
|
383
|
+
TXAudioEffectManager getAudioEffectManager()
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
**Features**:
|
|
387
|
+
- **Background Music**: Supports online/local playback, speed/pitch adjustment, original/accompaniment, looping, etc.
|
|
388
|
+
- **Monitor (Earback)**: Real-time playback of microphone audio in headphones; commonly used for music streaming
|
|
389
|
+
- **Reverb Effects**: KTV, small room, auditorium, deep, bright, etc.
|
|
390
|
+
- **Voice Changer Effects**: Child, uncle, heavy metal, etc.
|
|
391
|
+
- **Short Sound Effects**: Supports short audio files (e.g., applause, laughter). For files under 10 seconds, set `isShortFile` to `true`.
|
|
392
|
+
|
|
393
|
+
### getDeviceManager
|
|
394
|
+
**Purpose**: Access the device manager
|
|
395
|
+
```dart
|
|
396
|
+
TXDeviceManager getDeviceManager()
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
## Advanced Features
|
|
400
|
+
|
|
401
|
+
### snapshot
|
|
402
|
+
**Purpose**: Capture a snapshot of local video during streaming
|
|
403
|
+
```dart
|
|
404
|
+
Future<V2TXLiveCode> snapshot()
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
**Returns**:
|
|
408
|
+
- `V2TXLIVE_OK`: Success
|
|
409
|
+
- `V2TXLIVE_ERROR_REFUSED`: Streaming stopped; cannot capture snapshot
|
|
410
|
+
|
|
411
|
+
### enableVolumeEvaluation
|
|
412
|
+
**Purpose**: Enable capture volume indication
|
|
413
|
+
```dart
|
|
414
|
+
Future<V2TXLiveCode> enableVolumeEvaluation(int intervalMs)
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
**Parameters**:
|
|
418
|
+
- `intervalMs`: Volume callback interval (ms); minimum 100ms. Set ≤0 to disable. Recommended: 300ms.
|
|
419
|
+
|
|
420
|
+
### enableCustomVideoProcess
|
|
421
|
+
**Purpose**: Enable or disable custom video processing
|
|
422
|
+
```dart
|
|
423
|
+
Future<V2TXLiveCode> enableCustomVideoProcess(bool enable, V2TXLivePixelFormat pixelFormat, V2TXLiveBufferType bufferType)
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
**Parameters**:
|
|
427
|
+
- `enable`: Enable (true) or disable (false); default is false
|
|
428
|
+
- `pixelFormat`: Pixel format for custom pre-processing callback [V2TXLivePixelFormat]
|
|
429
|
+
- `bufferType`: Data format for custom pre-processing callback [V2TXLiveBufferType]
|
|
430
|
+
|
|
431
|
+
**Supported Combinations**:
|
|
432
|
+
- `V2TXLivePixelFormatTexture2D` + `V2TXLiveBufferTypeTexture`
|
|
433
|
+
- `V2TXLivePixelFormatI420` + `V2TXLiveBufferTypeByteBuffer`
|
|
434
|
+
|
|
435
|
+
### enableCustomVideoCapture
|
|
436
|
+
**Purpose**: Enable or disable custom video capture
|
|
437
|
+
```dart
|
|
438
|
+
Future<V2TXLiveCode> enableCustomVideoCapture(bool enable)
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
**Parameters**:
|
|
442
|
+
- `enable`: Enable custom capture (true) or disable (false); default is false
|
|
443
|
+
|
|
444
|
+
**Note**: When enabled, the SDK does not capture images from the camera, only encodes and sends. Call before [startPush] to take effect.
|
|
445
|
+
|
|
446
|
+
### enableCustomAudioCapture
|
|
447
|
+
**Purpose**: Enable or disable custom audio capture
|
|
448
|
+
```dart
|
|
449
|
+
Future<V2TXLiveCode> enableCustomAudioCapture(bool enable)
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
**Parameters**:
|
|
453
|
+
- `enable`: Enable custom capture (true) or disable (false); default is false
|
|
454
|
+
|
|
455
|
+
**Note**: When enabled, the SDK does not capture audio from the microphone, only encodes and sends. Call before [startPush] to take effect.
|
|
456
|
+
|
|
457
|
+
### sendCustomVideoFrame
|
|
458
|
+
**Purpose**: Send custom video frame data to the SDK in custom video capture mode
|
|
459
|
+
```dart
|
|
460
|
+
Future<V2TXLiveCode> sendCustomVideoFrame(V2TXLiveVideoFrame videoFrame)
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
**Parameters**:
|
|
464
|
+
- `videoFrame`: Video frame data [V2TXLiveVideoFrame]
|
|
465
|
+
|
|
466
|
+
**Returns**:
|
|
467
|
+
- `V2TXLIVE_OK`: Success
|
|
468
|
+
- `V2TXLIVE_ERROR_INVALID_PARAMETER`: Failed; invalid video frame data
|
|
469
|
+
- `V2TXLIVE_ERROR_REFUSED`: Failed; must enable custom video capture first
|
|
470
|
+
|
|
471
|
+
### sendCustomAudioFrame
|
|
472
|
+
**Purpose**: Send custom audio frame data to the SDK in custom audio capture mode
|
|
473
|
+
```dart
|
|
474
|
+
Future<V2TXLiveCode> sendCustomAudioFrame(V2TXLiveAudioFrame audioFrame)
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
**Parameters**:
|
|
478
|
+
- `audioFrame`: Audio frame data [V2TXLiveAudioFrame]
|
|
479
|
+
|
|
480
|
+
**Returns**:
|
|
481
|
+
- `V2TXLIVE_OK`: Success
|
|
482
|
+
- `V2TXLIVE_ERROR_REFUSED`: Failed; must enable custom audio capture first
|
|
483
|
+
|
|
484
|
+
### sendSeiMessage
|
|
485
|
+
**Purpose**: Send SEI message
|
|
486
|
+
```dart
|
|
487
|
+
Future<V2TXLiveCode> sendSeiMessage(int payloadType, Uint8List data)
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
**Parameters**:
|
|
491
|
+
- `payloadType`: Data type; supports 5 and 242 (recommended)
|
|
492
|
+
- `data`: Data to send
|
|
493
|
+
|
|
494
|
+
**Description**: The player receives the message via the [V2TXLivePlayerListenerType.onReceiveSeiMessage] callback.
|
|
495
|
+
|
|
496
|
+
### showDebugView
|
|
497
|
+
**Purpose**: Show or hide the debug panel
|
|
498
|
+
```dart
|
|
499
|
+
Future<V2TXLiveCode> showDebugView(bool isShow)
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
**Parameters**:
|
|
503
|
+
- `isShow`: Show (true) or hide (false); default is false
|
|
504
|
+
|
|
505
|
+
### setProperty
|
|
506
|
+
**Purpose**: Call advanced API methods on V2TXLivePusher
|
|
507
|
+
```dart
|
|
508
|
+
Future<V2TXLiveCode> setProperty(String key, Object value)
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
**Parameters**:
|
|
512
|
+
- `key`: Advanced API key
|
|
513
|
+
- `value`: Parameter for the advanced API; basic type or jsonString
|
|
514
|
+
|
|
515
|
+
**Returns**:
|
|
516
|
+
- `V2TXLIVE_OK`: Success
|
|
517
|
+
- `V2TXLIVE_ERROR_INVALID_PARAMETER`: Failed; key cannot be empty
|
|
518
|
+
|
|
519
|
+
### setMixTranscodingConfig
|
|
520
|
+
**Purpose**: Configure cloud stream mixing transcoding parameters
|
|
521
|
+
```dart
|
|
522
|
+
Future<V2TXLiveCode> setMixTranscodingConfig(V2TXLiveTranscodingConfig? config)
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
**Parameters**:
|
|
526
|
+
- `config`: MixTranscoding configuration [V2TXLiveTranscodingConfig]; pass null to cancel cloud stream mixing
|
|
527
|
+
|
|
528
|
+
**Returns**: `V2TXLiveCode`
|
|
529
|
+
- `V2TXLIVE_OK`: Success
|
|
530
|
+
- `V2TXLIVE_ERROR_REFUSED`: Not allowed if streaming is not active
|
|
531
|
+
|
|
532
|
+
**Mixing Workflow**:
|
|
533
|
+
```
|
|
534
|
+
[Video 1] => Decoding ====> \
|
|
535
|
+
\
|
|
536
|
+
[Video 2] => Decoding => Video Mixing => Encoding => [Mixed Video]
|
|
537
|
+
/
|
|
538
|
+
[Video 3] => Decoding ====> /
|
|
539
|
+
|
|
540
|
+
[Audio 1] => Decoding ====> \
|
|
541
|
+
\
|
|
542
|
+
[Audio 2] => Decoding => Audio Mixing => Encoding => [Mixed Audio]
|
|
543
|
+
/
|
|
544
|
+
[Audio 3] => Decoding ====> /
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
**Notes**:
|
|
548
|
+
- **RTC protocol required for stream mixing**: This feature is only available with RTC protocol; not supported for RTMP or other protocols.
|
|
549
|
+
- Cloud transcoding adds 1–2 seconds of CDN viewing latency.
|
|
550
|
+
- Cancel mixing promptly by passing null to avoid unnecessary charges.
|
|
551
|
+
- Mixing is automatically cancelled when you Exit Room.
|
|
552
|
+
|
|
553
|
+
**When to Call**: During streaming
|
|
554
|
+
|
|
555
|
+
**Example**:
|
|
556
|
+
```dart
|
|
557
|
+
V2TXLiveTranscodingConfig config = V2TXLiveTranscodingConfig(
|
|
558
|
+
videoWidth: 1280,
|
|
559
|
+
videoHeight: 720,
|
|
560
|
+
videoBitrate: 1500,
|
|
561
|
+
videoFps: 15
|
|
562
|
+
);
|
|
563
|
+
await pusher.setMixTranscodingConfig(config);
|
|
564
|
+
|
|
565
|
+
// Cancel mixing
|
|
566
|
+
await pusher.setMixTranscodingConfig(null);
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
## Code Examples
|
|
570
|
+
|
|
571
|
+
### Basic Streaming Example (Camera + Microphone)
|
|
572
|
+
```dart
|
|
573
|
+
import 'package:tencent_trtc/v2_tx_live_pusher.dart';
|
|
574
|
+
import 'package:tencent_trtc/v2_tx_live_pusher_observer.dart';
|
|
575
|
+
import 'package:tencent_trtc/v2_tx_live_def.dart';
|
|
576
|
+
import 'package:tencent_trtc/v2_tx_live_code.dart';
|
|
577
|
+
|
|
578
|
+
class BasicPushExample {
|
|
579
|
+
late V2TXLivePusher pusher;
|
|
580
|
+
|
|
581
|
+
Future<void> setupBasicPush() async {
|
|
582
|
+
// 1. Create pusher instance
|
|
583
|
+
pusher = await V2TXLivePusher.create(V2TXLiveMode.V2TXLiveModeRTC);
|
|
584
|
+
|
|
585
|
+
// 2. Register callback observer
|
|
586
|
+
pusher.addListener(V2TXLivePusherObserver(
|
|
587
|
+
onPushStatusUpdate: (status, msg, extraInfo) {
|
|
588
|
+
// Handle streaming status changes
|
|
589
|
+
switch (status) {
|
|
590
|
+
case V2TXLivePushStatus.V2TXLivePushStatusDisconnected:
|
|
591
|
+
print('Streaming connection disconnected');
|
|
592
|
+
break;
|
|
593
|
+
case V2TXLivePushStatus.V2TXLivePushStatusConnecting:
|
|
594
|
+
print('Connecting to streaming server');
|
|
595
|
+
break;
|
|
596
|
+
case V2TXLivePushStatus.V2TXLivePushStatusConnectSuccess:
|
|
597
|
+
print('Streaming connection successful');
|
|
598
|
+
break;
|
|
599
|
+
case V2TXLivePushStatus.V2TXLivePushStatusReconnecting:
|
|
600
|
+
print('Reconnecting streaming');
|
|
601
|
+
break;
|
|
602
|
+
}
|
|
603
|
+
},
|
|
604
|
+
onStatisticsUpdate: (statistics) {
|
|
605
|
+
// Handle statistics
|
|
606
|
+
print('App CPU: ${statistics.appCpu}%, System CPU: ${statistics.systemCpu}%');
|
|
607
|
+
print('Width: ${statistics.width}, Height: ${statistics.height}');
|
|
608
|
+
print('FPS: ${statistics.fps}, Video Bitrate: ${statistics.videoBitrate}');
|
|
609
|
+
print('Audio Bitrate: ${statistics.audioBitrate}');
|
|
610
|
+
},
|
|
611
|
+
onError: (code, msg, extraInfo) {
|
|
612
|
+
// Handle error information
|
|
613
|
+
print('Streaming error: code=$code, msg=$msg');
|
|
614
|
+
}
|
|
615
|
+
));
|
|
616
|
+
|
|
617
|
+
// 3. Set preview view
|
|
618
|
+
await pusher.setRenderViewID(yourTextureViewID);
|
|
619
|
+
|
|
620
|
+
// 4. Start at least one capture source before streaming
|
|
621
|
+
// Start camera capture (front camera)
|
|
622
|
+
await pusher.startCamera(true);
|
|
623
|
+
|
|
624
|
+
// Start microphone capture
|
|
625
|
+
await pusher.startMicrophone();
|
|
626
|
+
|
|
627
|
+
// 5. Start streaming
|
|
628
|
+
String pushUrl = "rtmp://your-push-server/live/streamid";
|
|
629
|
+
V2TXLiveCode result = await pusher.startPush(pushUrl);
|
|
630
|
+
|
|
631
|
+
if (result == V2TXLiveCode.V2TXLIVE_OK) {
|
|
632
|
+
print('✅ Streaming started successfully');
|
|
633
|
+
} else if (result == V2TXLiveCode.V2TXLIVE_ERROR_INVALID_PARAMETER) {
|
|
634
|
+
print('❌ Invalid streaming address');
|
|
635
|
+
} else if (result == V2TXLiveCode.V2TXLIVE_ERROR_INVALID_LICENSE) {
|
|
636
|
+
print('❌ Invalid Licence, please check your Licence');
|
|
637
|
+
} else if (result == V2TXLiveCode.V2TXLIVE_ERROR_REFUSED) {
|
|
638
|
+
print('❌ Call refused');
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
Future<void> stopPush() async {
|
|
643
|
+
// Stop streaming
|
|
644
|
+
await pusher.stopPush();
|
|
645
|
+
// Stop capture sources
|
|
646
|
+
await pusher.stopCamera();
|
|
647
|
+
await pusher.stopMicrophone();
|
|
648
|
+
// Destroy instance
|
|
649
|
+
pusher.destroy();
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
```
|
|
653
|
+
|
|
654
|
+
### Advanced Configuration Example
|
|
655
|
+
|
|
656
|
+
```dart
|
|
657
|
+
// Set video encoding parameters
|
|
658
|
+
V2TXLiveVideoEncoderParam videoParam = V2TXLiveVideoEncoderParam(
|
|
659
|
+
videoResolution: V2TXLiveVideoResolution.v2TXLiveVideoResolution1280x720,
|
|
660
|
+
videoResolutionMode: V2TXLiveVideoResolutionMode.v2TXLiveVideoResolutionModeLandscape,
|
|
661
|
+
videoFps: 15,
|
|
662
|
+
videoBitrate: 1200,
|
|
663
|
+
minVideoBitrate: 800,
|
|
664
|
+
);
|
|
665
|
+
await pusher.setVideoQuality(videoParam);
|
|
666
|
+
|
|
667
|
+
// Set audio quality
|
|
668
|
+
await pusher.setAudioQuality(V2TXLiveAudioQuality.v2TXLiveAudioQualityMusic);
|
|
669
|
+
|
|
670
|
+
// Enable volume evaluation
|
|
671
|
+
await pusher.enableVolumeEvaluation(300);
|
|
672
|
+
|
|
673
|
+
// Show debug panel
|
|
674
|
+
await pusher.showDebugView(true);
|
|
675
|
+
```
|
|
676
|
+
|
|
677
|
+
### Custom Capture Example
|
|
678
|
+
|
|
679
|
+
```dart
|
|
680
|
+
// Enable custom video capture
|
|
681
|
+
await pusher.enableCustomVideoCapture(true);
|
|
682
|
+
|
|
683
|
+
// Custom video frame processing
|
|
684
|
+
V2TXLiveVideoFrame videoFrame = V2TXLiveVideoFrame(
|
|
685
|
+
pixelFormat: V2TXLivePixelFormat.v2TXLivePixelFormatI420,
|
|
686
|
+
bufferType: V2TXLiveBufferType.v2TXLiveBufferTypeByteBuffer,
|
|
687
|
+
data: yourVideoData,
|
|
688
|
+
width: 640,
|
|
689
|
+
height: 480,
|
|
690
|
+
rotation: V2TXLiveRotation.v2TXLiveRotation0,
|
|
691
|
+
);
|
|
692
|
+
|
|
693
|
+
// Send custom video frame
|
|
694
|
+
await pusher.sendCustomVideoFrame(videoFrame);
|
|
695
|
+
```
|
|
696
|
+
|
|
697
|
+
## Notes
|
|
698
|
+
|
|
699
|
+
### 1. Capture Source Requirements
|
|
700
|
+
**You must start at least one capture source before streaming; otherwise, streaming will fail:**
|
|
701
|
+
- **Camera capture**: `startCamera()` + `startMicrophone()`
|
|
702
|
+
- **Screen capture**: `startScreenCapture()` + `startMicrophone()`
|
|
703
|
+
- **Image streaming**: `startVirtualCamera()` + `startMicrophone()`
|
|
704
|
+
- **Custom capture**: `enableCustomVideoCapture()` + `enableCustomAudioCapture()`
|
|
705
|
+
- **Audio-only streaming**: `startMicrophone()`
|
|
706
|
+
|
|
707
|
+
### 2. Capture Source Switching Rules
|
|
708
|
+
- Only one capture source can be active per pusher instance.
|
|
709
|
+
- To switch sources, stop the current source before starting a new one.
|
|
710
|
+
|
|
711
|
+
### 3. Call Sequence Requirements
|
|
712
|
+
1. Create pusher instance
|
|
713
|
+
2. Register callbacks and set preview view
|
|
714
|
+
3. Start at least one capture source
|
|
715
|
+
4. Call `startPush()` to begin streaming
|
|
716
|
+
|
|
717
|
+
### 4. Custom Capture Guidelines
|
|
718
|
+
- Call custom capture-related methods before `startPush` to take effect.
|
|
719
|
+
- In custom capture mode, the SDK only encodes and sends data; it does not perform actual capture.
|
|
720
|
+
|
|
721
|
+
### 5. Cloud Stream Mixing Guidelines
|
|
722
|
+
- **Protocol restriction**: Cloud stream mixing is only supported with RTC protocol; not available for RTMP or other protocols.
|
|
723
|
+
- Cancel mixing promptly to avoid unnecessary charges.
|
|
724
|
+
- Cloud transcoding adds 1–2 seconds of CDN viewing latency.
|
|
725
|
+
|
|
726
|
+
### 6. Local Recording Guidelines
|
|
727
|
+
- Recording can only start after streaming begins.
|
|
728
|
+
- Do not change resolution or switch between hardware/software encoding during recording.
|
|
729
|
+
|
|
730
|
+
### 7. System Audio Capture Requirements
|
|
731
|
+
- Requires Android API 29 or higher.
|
|
732
|
+
- Must use a foreground service to prevent capture from being silenced.
|
|
733
|
+
- Only effective during screen sharing.
|
|
734
|
+
|
|
735
|
+
### 8. Performance Optimization Tips
|
|
736
|
+
- Choose audio/video quality settings appropriate for your scenario.
|
|
737
|
+
- Release unused pusher instances promptly.
|
|
738
|
+
- Use pause/resume features to conserve bandwidth.
|
|
739
|
+
|
|
740
|
+
### 9. Error Handling Recommendations
|
|
741
|
+
- Handle the `onError` callback and notify users appropriately.
|
|
742
|
+
- The SDK automatically reconnects on network exceptions; no manual intervention required.
|
|
743
|
+
- Update Licence configuration promptly when it expires.
|
|
744
|
+
|
|
745
|
+
### 10. Permissions and Resource Management
|
|
746
|
+
- Ensure your app has camera and microphone permissions.
|
|
747
|
+
- Call `destroy` promptly to release resources.
|
|
748
|
+
- Prevent memory leaks by removing observers in a timely manner.
|