Skip to content

Commit

Permalink
No configuration required WOWZA when constructing WOWZCameraView
Browse files Browse the repository at this point in the history
  • Loading branch information
VNAPNIC committed Mar 16, 2020
1 parent 12c433f commit 4d9ee39
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 88 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.6

* No configuration required WOWZA when constructing WOWZCameraView

## 0.1.5

* fix Android permission not working
Expand Down
25 changes: 15 additions & 10 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'package:flutter_wowza/gocoder/wowza_gocoder.dart';

Expand All @@ -18,6 +19,16 @@ class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
SchedulerBinding.instance.addPostFrameCallback((_) {
controller.setWOWZConfig(
hostAddress: "xxx.xxx.xxx.xxx",
portNumber: 1935,
applicationName: "xxxxxx",
streamName: "xxxxx",
username: "xxxx",
password: "xxxx",
scaleMode: ScaleMode.FILL_VIEW);
});
}

@override
Expand All @@ -34,17 +45,11 @@ class _MyAppState extends State<MyApp> {
height: 720,
width: 1280,
child: WOWZCameraView(
apiLicenseKey: (defaultTargetPlatform == TargetPlatform.android)
? "GOSK-9C47-010C-2895-D225-9FEF"
: "GOSK-9C47-010C-A9B9-EB78-3FBD",
apiLicenseKey:
(defaultTargetPlatform == TargetPlatform.android)
? "GOSK-9C47-010C-2895-D225-9FEF"
: "GOSK-9C47-010C-A9B9-EB78-3FBD",
controller: controller,
hostAddress: "xxx.xxx.xxx.xxx",
portNumber: 1935,
applicationName: "xxxxxx",
streamName: "xxxxx",
username: "xxxx",
password: "xxxx",
scaleMode: ScaleMode.FILL_VIEW,
statusCallback: (status) {
print(
"status: ${status.mState} | ${status.isStarting()} | ${status.isReady()}");
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.4"
version: "0.1.5"
image:
dependency: transitive
description:
Expand Down
143 changes: 143 additions & 0 deletions lib/gocoder/src/wowz_camera_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,155 @@ class CameraControllerValue {
class WOWZCameraController extends ValueNotifier<CameraControllerValue> {
MethodChannel _channel;

// Set the connection properties for the target Wowza Streaming Engine server or Wowza Streaming Cloud live stream
String hostAddress;
int portNumber;
String applicationName;
String streamName;

//authentication
String username;
String password;

WOWZSize wowzSize;
WOWZMediaConfig wowzMediaConfig;
ScaleMode scaleMode;

int fps;
int bps;
int khz;

bool configIsWaiting = false;

_setChannel(MethodChannel channel) {
_channel = channel;
}

WOWZCameraController() : super(CameraControllerValue());

/// It will not execute immediately when the chanel has not been initialized,
/// and it will wait until the channel is initialized and it will automatically execute the config.
setWOWZConfig(
{@required String hostAddress,
@required int portNumber,
@required String applicationName,
@required String streamName,
String username,
String password,
WOWZSize wowzSize,
WOWZMediaConfig wowzMediaConfig,
ScaleMode scaleMode,
int fps,
int bps,
int khz}) {

if (_channel == null) {
this.hostAddress = hostAddress;
this.portNumber = portNumber;
this.applicationName = applicationName;
this.streamName = streamName;
this.username = username;
this.password = password;
this.wowzSize = wowzSize;
this.wowzMediaConfig = wowzMediaConfig;
this.scaleMode = scaleMode;
this.fps = fps;
this.bps = bps;
this.khz = khz;
this.configIsWaiting = true;
return;
}

configIsWaiting = false;

// Set the connection properties for the target Wowza Streaming Engine server or Wowza Streaming Cloud live stream
if (hostAddress != null && hostAddress.isNotEmpty) {
_channel.invokeMethod(_hostAddress, hostAddress);
}
if (portNumber != null) {
_channel.invokeMethod(_portNumber, portNumber);
}
if (applicationName != null && applicationName.isNotEmpty) {
_channel.invokeMethod(_applicationName, applicationName);
}
if (streamName != null && streamName.isNotEmpty) {
_channel.invokeMethod(_streamName, streamName);
}
//authentication
if (username != null) {
_channel.invokeMethod(_username, username);
}
if (password != null) {
_channel.invokeMethod(_password, password);
}
if (wowzSize != null) {
_channel.invokeMethod(_wowzSize, "${wowzSize.width}/${wowzSize.height}");
}
if (wowzMediaConfig != null) {
_channel.invokeMethod(_wowzMediaConfig, wowzMediaConfig.toString());
}
if (scaleMode != null) {
_channel.invokeMethod(_scaleMode, scaleMode.toString());
}
if (fps != null) {
_channel.invokeListMethod(_fps, fps);
}
if (bps != null) {
_channel.invokeListMethod(_bps, bps);
}
if (khz != null) {
_channel.invokeListMethod(_bps, bps);
}

_channel.invokeListMethod(_initGoCoder);
}

/// Restore settings set in the [setWOWZConfig] method
resetConfig(){
configIsWaiting = false;

// Set the connection properties for the target Wowza Streaming Engine server or Wowza Streaming Cloud live stream
if (hostAddress != null && hostAddress.isNotEmpty) {
_channel.invokeMethod(_hostAddress, hostAddress);
}
if (portNumber != null) {
_channel.invokeMethod(_portNumber, portNumber);
}
if (applicationName != null && applicationName.isNotEmpty) {
_channel.invokeMethod(_applicationName, applicationName);
}
if (streamName != null && streamName.isNotEmpty) {
_channel.invokeMethod(_streamName, streamName);
}
//authentication
if (username != null) {
_channel.invokeMethod(_username, username);
}
if (password != null) {
_channel.invokeMethod(_password, password);
}
if (wowzSize != null) {
_channel.invokeMethod(_wowzSize, "${wowzSize.width}/${wowzSize.height}");
}
if (wowzMediaConfig != null) {
_channel.invokeMethod(_wowzMediaConfig, wowzMediaConfig.toString());
}
if (scaleMode != null) {
_channel.invokeMethod(_scaleMode, scaleMode.toString());
}
if (fps != null) {
_channel.invokeListMethod(_fps, fps);
}
if (bps != null) {
_channel.invokeListMethod(_bps, bps);
}
if (khz != null) {
_channel.invokeListMethod(_bps, bps);
}

_channel.invokeListMethod(_initGoCoder);
}

/// Starts the camera preview display.
startPreview() {
value = CameraControllerValue(event: _startPreview);
Expand Down
92 changes: 16 additions & 76 deletions lib/gocoder/src/wowz_camera_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,16 @@ enum ScaleMode {
typedef WOWZStatusCallback = Function(WOWZStatus);
typedef WOWZBroadcastStatusCallback = Function(WOWZBroadcastStatus);

abstract class OnWOWZBroadcastStatusCallback{
abstract class OnWOWZBroadcastStatusCallback {
void onWZStatus(WOWZBroadcastStatus status);

void onWZError(WOWZBroadcastStatus status);
}

class WOWZCameraView extends StatefulWidget {
WOWZCameraView(
{@required this.controller,
@required this.apiLicenseKey,
@required this.hostAddress,
@required this.portNumber,
@required this.applicationName,
@required this.streamName,
this.username,
this.password,
this.wowzSize,
this.wowzMediaConfig,
this.scaleMode = ScaleMode.RESIZE_TO_ASPECT, this.fps, this.bps, this.khz,
this.statusCallback,
this.broadcastStatusCallback});

Expand All @@ -84,24 +76,6 @@ class WOWZCameraView extends StatefulWidget {
final WOWZBroadcastStatusCallback broadcastStatusCallback;

final String apiLicenseKey;

// Set the connection properties for the target Wowza Streaming Engine server or Wowza Streaming Cloud live stream
final String hostAddress;
final int portNumber;
final String applicationName;
final String streamName;

//authentication
final String username;
final String password;

final WOWZSize wowzSize;
final WOWZMediaConfig wowzMediaConfig;
final ScaleMode scaleMode;

final int fps;
final int bps;
final int khz;
}

class _WOWZCameraViewState extends State<WOWZCameraView> {
Expand All @@ -116,18 +90,21 @@ class _WOWZCameraViewState extends State<WOWZCameraView> {
print('controller event: ${widget.controller.value.event}');
switch (widget.controller.value.event) {
case _flashlight:
if(defaultTargetPlatform == TargetPlatform.android)
if (defaultTargetPlatform == TargetPlatform.android)
_channel?.invokeMethod(
widget.controller.value.event, widget.controller.value.value);
else
_channel?.invokeMethod(widget.controller.value.value?_flashlightOn:_flashlightOff);
_channel?.invokeMethod(widget.controller.value.value
? _flashlightOn
: _flashlightOff);
break;
case _muted:
if(defaultTargetPlatform == TargetPlatform.android)
if (defaultTargetPlatform == TargetPlatform.android)
_channel?.invokeMethod(
widget.controller.value.event, widget.controller.value.value);
else
_channel?.invokeMethod(widget.controller.value.value?_mutedOn:_mutedOff);
_channel?.invokeMethod(
widget.controller.value.value ? _mutedOn : _mutedOff);
break;
case _startPreview:
case _startPreview:
Expand Down Expand Up @@ -169,10 +146,13 @@ class _WOWZCameraViewState extends State<WOWZCameraView> {
'$defaultTargetPlatform is not yet supported by the text_view plugin');
}

_onPlatformViewCreated(int viewId){
_onPlatformViewCreated(int viewId) {
if (_viewId != viewId || _channel == null) {
_viewId = viewId;

_channel = MethodChannel("${_camera_view_channel}_$viewId");
widget.controller?._setChannel(_channel);

_channel.setMethodCallHandler((call) async {
print('wowz: status: ${call.arguments}');
switch (call.method) {
Expand All @@ -192,52 +172,12 @@ class _WOWZCameraViewState extends State<WOWZCameraView> {
break;
}
});
widget.controller?._setChannel(_channel);

// license key gocoder sdk
_channel.invokeMethod(_apiLicenseKey, widget.apiLicenseKey);
// Set the connection properties for the target Wowza Streaming Engine server or Wowza Streaming Cloud live stream
if (widget.hostAddress != null && widget.hostAddress.isNotEmpty) {
_channel.invokeMethod(_hostAddress, widget.hostAddress);
}
if (widget.portNumber != null) {
_channel.invokeMethod(_portNumber, widget.portNumber);
}
if (widget.applicationName != null && widget.applicationName.isNotEmpty) {
_channel.invokeMethod(_applicationName, widget.applicationName);
}
if (widget.streamName != null && widget.streamName.isNotEmpty) {
_channel.invokeMethod(_streamName, widget.streamName);
}
//authentication
if (widget.username != null) {
_channel.invokeMethod(_username, widget.username);
}
if (widget.password != null) {
_channel.invokeMethod(_password, widget.password);
}
if (widget.wowzSize != null) {
_channel.invokeMethod(
_wowzSize, "${widget.wowzSize.width}/${widget.wowzSize.height}");
}
if (widget.wowzMediaConfig != null) {
_channel.invokeMethod(
_wowzMediaConfig, widget.wowzMediaConfig.toString());
}
if (widget.scaleMode != null) {
_channel.invokeMethod(_scaleMode, widget.scaleMode.toString());
}
if(widget.fps!=null){
_channel.invokeListMethod(_fps,widget.fps);
}
if(widget.bps !=null){
_channel.invokeListMethod(_bps,widget.bps);
}
if(widget.khz !=null){
_channel.invokeListMethod(_bps,widget.bps);
}

_channel.invokeListMethod(_initGoCoder);
if (widget.controller.configIsWaiting) {
widget.controller.resetConfig();
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: flutter_wowza
description: Flutter WOWZA plugin for iOS/Android. The project is based on Wowza GoCoder SDK
homepage: https://github.com/VNAPNIC/flutter-wowza
version: 0.1.5
version: 0.1.6
author: vn.apnic@gmail.comn

environment:
Expand Down

0 comments on commit 4d9ee39

Please sign in to comment.