Java Code Examples for com.qiniu.pili.droid.streaming.StreamingProfile

The following examples show how to use com.qiniu.pili.droid.streaming.StreamingProfile. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: pili-react-native   Source File: PiliStreamingViewManager.java    License: MIT License 6 votes vote down vote up
@ReactProp(name = "profile")
public void setProfile(AspectFrameLayout view, @Nullable ReadableMap profile) {
    ReadableMap video = profile.getMap("video");
    ReadableMap audio = profile.getMap("audio");
    int encodingSize = profile.getInt("encodingSize");

    StreamingProfile.AudioProfile aProfile =
            new StreamingProfile.AudioProfile(audio.getInt("rate"), audio.getInt("bitrate")); //audio sample rate, audio bitrate
    StreamingProfile.VideoProfile vProfile =
            new StreamingProfile.VideoProfile(video.getInt("fps"), video.getInt("bps"), video.getInt("maxFrameInterval"));//fps bps maxFrameInterval
    StreamingProfile.AVProfile avProfile = new StreamingProfile.AVProfile(vProfile, aProfile);
    mProfile.setAVProfile(avProfile);
    mProfile.setEncodingSizeLevel(encodingSize);
    mMediaStreamingManager.setStreamingProfile(mProfile);

}
 
Example 2
Source Project: react-native-pili   Source File: PiliStreamingViewManager.java    License: MIT License 6 votes vote down vote up
@ReactProp(name = "profile")
public void setProfile(AspectFrameLayout view, @Nullable ReadableMap profile) {
    ReadableMap video = profile.getMap("video");
    ReadableMap audio = profile.getMap("audio");
    int encodingSize = profile.getInt("encodingSize");

    StreamingProfile.AudioProfile aProfile =
            new StreamingProfile.AudioProfile(audio.getInt("rate"), audio.getInt("bitrate")); //audio sample rate, audio bitrate
    StreamingProfile.VideoProfile vProfile =
            new StreamingProfile.VideoProfile(video.getInt("fps"), video.getInt("bps"), video.getInt("maxFrameInterval"));//fps bps maxFrameInterval
    StreamingProfile.AVProfile avProfile = new StreamingProfile.AVProfile(vProfile, aProfile);
    mProfile.setAVProfile(avProfile);
    mProfile.setEncodingSizeLevel(encodingSize);
    mMediaStreamingManager.setStreamingProfile(mProfile);

}
 
Example 3
Source Project: PLDroidMediaStreaming   Source File: AVStreamingActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Camera.Size onPreviewSizeSelected(List<Camera.Size> list) {
    /**
     * You should choose a suitable size to avoid image scale
     * eg: If streaming size is 1280 x 720, you should choose a camera preview size >= 1280 x 720
     */
    Camera.Size size = null;
    if (list != null) {
        StreamingProfile.VideoEncodingSize encodingSize = mProfile.getVideoEncodingSize(mCameraConfig.mSizeRatio);
        for (Camera.Size s : list) {
            if (s.width >= encodingSize.width && s.height >= encodingSize.height) {
                if (mEncodingConfig.mIsVideoSizePreset) {
                    size = s;
                    Log.d(TAG, "selected size :" + size.width + "x" + size.height);
                }
                break;
            }
        }
    }
    return size;
}
 
Example 4
Source Project: pili-react-native   Source File: PiliAudioStreamingViewManager.java    License: MIT License 5 votes vote down vote up
@ReactProp(name = "profile")
public void setProfile(View view, @Nullable ReadableMap profile) {
    ReadableMap audio = profile.getMap("audio");

    StreamingProfile.VideoProfile vProfile =
            new StreamingProfile.VideoProfile(0,0,0);//hack for bad API

    StreamingProfile.AudioProfile aProfile =
            new StreamingProfile.AudioProfile(audio.getInt("rate"), audio.getInt("bitrate")); //audio sample rate, audio bitrate
    StreamingProfile.AVProfile avProfile = new StreamingProfile.AVProfile(vProfile, aProfile);
    mProfile.setAVProfile(avProfile);
    mMediaStreamingManager.setStreamingProfile(mProfile);

}
 
Example 5
Source Project: PLDroidRTCStreaming   Source File: PKAnchorActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void notifyStreamStatusChanged(final StreamingProfile.StreamStatus streamStatus) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            String stat = "bitrate: " + streamStatus.totalAVBitrate / 1024 + " kbps"
                    + "\naudio: " + streamStatus.audioFps + " fps"
                    + "\nvideo: " + streamStatus.videoFps + " fps";
            mStatTextView.setText(stat);
        }
    });
}
 
Example 6
Source Project: PLDroidRTCStreaming   Source File: RTCStreamingActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void notifyStreamStatusChanged(final StreamingProfile.StreamStatus streamStatus) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            String stat = "bitrate: " + streamStatus.totalAVBitrate / 1024 + " kbps"
                    + "\naudio: " + streamStatus.audioFps + " fps"
                    + "\nvideo: " + streamStatus.videoFps + " fps";
            mStatTextView.setText(stat);
        }
    });
}
 
Example 7
@Override
public void notifyStreamStatusChanged(final StreamingProfile.StreamStatus streamStatus) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            String stat = "bitrate: " + streamStatus.totalAVBitrate / 1024 + " kbps"
                    + "\naudio: " + streamStatus.audioFps + " fps"
                    + "\nvideo: " + streamStatus.videoFps + " fps";
            mStatTextView.setText(stat);
        }
    });
}
 
Example 8
@Override
public void notifyStreamStatusChanged(final StreamingProfile.StreamStatus streamStatus) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            String stat = "Bitrate: " + streamStatus.totalAVBitrate / 1024 + " kbps"
                    + "\nAudio: " + streamStatus.audioFps + " fps";
            mStatTextView.setText(stat);
        }
    });
}
 
Example 9
Source Project: react-native-pili   Source File: PiliAudioStreamingViewManager.java    License: MIT License 5 votes vote down vote up
@ReactProp(name = "profile")
public void setProfile(View view, @Nullable ReadableMap profile) {
    ReadableMap audio = profile.getMap("audio");

    StreamingProfile.VideoProfile vProfile =
            new StreamingProfile.VideoProfile(0,0,0);//hack for bad API

    StreamingProfile.AudioProfile aProfile =
            new StreamingProfile.AudioProfile(audio.getInt("rate"), audio.getInt("bitrate")); //audio sample rate, audio bitrate
    StreamingProfile.AVProfile avProfile = new StreamingProfile.AVProfile(vProfile, aProfile);
    mProfile.setAVProfile(avProfile);
    mMediaStreamingManager.setStreamingProfile(mProfile);

}
 
Example 10
Source Project: PLDroidMediaStreaming   Source File: AVStreamingActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    Log.i(TAG, "mIsEncOrientationPort:" + mIsEncOrientationPort);
    mOrientationChanged = true;
    mIsEncOrientationPort = !mIsEncOrientationPort;
    mProfile.setEncodingOrientation(mIsEncOrientationPort ? StreamingProfile.ENCODING_ORIENTATION.PORT : StreamingProfile.ENCODING_ORIENTATION.LAND);
    mMediaStreamingManager.setStreamingProfile(mProfile);
    stopStreamingInternal();
    setRequestedOrientation(mIsEncOrientationPort ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    mMediaStreamingManager.notifyActivityOrientationChanged();
    updateOrientationBtnText();
    Toast.makeText(AVStreamingActivity.this, Config.HINT_ENCODING_ORIENTATION_CHANGED,
            Toast.LENGTH_SHORT).show();
    Log.i(TAG, "EncodingOrientationSwitcher -");
}
 
Example 11
@Override
public void notifyStreamStatusChanged(final StreamingProfile.StreamStatus streamStatus) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            mStatView.setText("bitrate:" + streamStatus.totalAVBitrate / 1024 + " kbps"
                    + "\naudio:" + streamStatus.audioFps + " fps"
                    + "\nvideo:" + streamStatus.videoFps + " fps");
        }
    });
}
 
Example 12
/**
 * 更新推流参数
 */
private void setStreamingProfile(MethodCall call, final MethodChannel.Result result) {
    this.streamingProfile = JSON.parseObject(CommonUtil.getParam(call, result, "streamingProfile").toString(), StreamingProfile.class);
    manager.setStreamingProfile(streamingProfile);
    result.success(null);
}
 
Example 13
@Override
public void notifyStreamStatusChanged(StreamingProfile.StreamStatus streamStatus) {
    invokeListener(PushCallBackNoticeEnum.StreamStatusChanged, streamStatus);
}
 
Example 14
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setContentView(R.layout.activity_audio_streaming);

    mRole = getIntent().getIntExtra("role", QiniuAppServer.RTC_ROLE_VICE_ANCHOR);
    mRoomName = getIntent().getStringExtra("roomName");
    boolean isSwCodec = getIntent().getBooleanExtra("swcodec", true);
    boolean isLandscape = getIntent().getBooleanExtra("orientation", false);
    mIsAudioLevelCallbackEnabled = getIntent().getBooleanExtra("audioLevelCallback", false);
    setRequestedOrientation(isLandscape ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    mControlButton = (Button) findViewById(R.id.ControlButton);
    mStatusTextView = (TextView) findViewById(R.id.StatusTextView);
    mStatTextView = (TextView) findViewById(R.id.StatTextView);
    mMuteCheckBox = (CheckBox) findViewById(R.id.MuteCheckBox);
    mMuteCheckBox.setOnClickListener(mMuteButtonClickListener);
    mConferenceCheckBox = (CheckBox) findViewById(R.id.ConferenceCheckBox);
    mConferenceCheckBox.setOnClickListener(mConferenceButtonClickListener);

    if (mRole == QiniuAppServer.RTC_ROLE_ANCHOR) {
        mConferenceCheckBox.setVisibility(View.VISIBLE);
    }

    AVCodecType codecType = isSwCodec ? AVCodecType.SW_AUDIO_CODEC : AVCodecType.HW_AUDIO_CODEC;
    mRTCStreamingManager = new RTCMediaStreamingManager(getApplicationContext(), codecType);
    mRTCStreamingManager.setConferenceStateListener(mRTCStreamingStateChangedListener);
    mRTCStreamingManager.setUserEventListener(mRTCUserEventListener);
    mRTCStreamingManager.setDebugLoggingEnabled(false);

    if (mIsAudioLevelCallbackEnabled) {
        mRTCStreamingManager.setAudioLevelCallback(mRTCAudioLevelCallback);
    }

    RTCConferenceOptions options = new RTCConferenceOptions();
    options.setHWCodecEnabled(!isSwCodec);
    mRTCStreamingManager.setConferenceOptions(options);

    // the anchor must configure the `StreamingProfile`
    if (mRole == QiniuAppServer.RTC_ROLE_ANCHOR) {
        mRTCStreamingManager.setStreamStatusCallback(mStreamStatusCallback);
        mRTCStreamingManager.setStreamingStateListener(mStreamingStateChangedListener);
        mRTCStreamingManager.setStreamingSessionListener(mStreamingSessionListener);

        mStreamingProfile = new StreamingProfile();
        mStreamingProfile.setAudioQuality(StreamingProfile.AUDIO_QUALITY_MEDIUM2)
                .setEncoderRCMode(StreamingProfile.EncoderRCModes.QUALITY_PRIORITY);
        mRTCStreamingManager.prepare(null,  mStreamingProfile);
    } else {
        /**
         * The RTCVideoWindow is used to show the anchor's video
         * This code is not required when the anchor is publishing audio streaming only.
         */
        RTCVideoWindow remoteAnchorView = new RTCVideoWindow((RTCSurfaceView) findViewById(R.id.RemoteAnchorView));
        mRTCStreamingManager.addRemoteWindow(remoteAnchorView);

        mControlButton.setText("开始连麦");
        mRTCStreamingManager.prepare(null);
    }

    mProgressDialog = new ProgressDialog(this);
}
 
Example 15
private void initEncodingProfile() {
    mEncodingConfig = (EncodingConfig) getIntent().getSerializableExtra("EncodingConfig");

    StreamingProfile.AudioProfile aProfile = null;
    StreamingProfile.VideoProfile vProfile = null;

    if (!mEncodingConfig.mIsAudioOnly) {
        // video quality
        if (mEncodingConfig.mIsVideoQualityPreset) {
            mProfile.setVideoQuality(mEncodingConfig.mVideoQualityPreset);
        } else {
            vProfile = new StreamingProfile.VideoProfile(
                    mEncodingConfig.mVideoQualityCustomFPS,
                    mEncodingConfig.mVideoQualityCustomBitrate * 1024,
                    mEncodingConfig.mVideoQualityCustomMaxKeyFrameInterval,
                    mEncodingConfig.mVideoQualityCustomProfile
            );
        }

        // video size
        if (mEncodingConfig.mIsVideoSizePreset) {
            mProfile.setEncodingSizeLevel(mEncodingConfig.mVideoSizePreset);
        } else {
            mProfile.setPreferredVideoEncodingSize(mEncodingConfig.mVideoSizeCustomWidth, mEncodingConfig.mVideoSizeCustomHeight);
        }

        // video misc
        mProfile.setEncodingOrientation(mEncodingConfig.mVideoOrientationPortrait ? StreamingProfile.ENCODING_ORIENTATION.PORT : StreamingProfile.ENCODING_ORIENTATION.LAND);
        mProfile.setEncoderRCMode(mEncodingConfig.mVideoRateControlQuality ? StreamingProfile.EncoderRCModes.QUALITY_PRIORITY : StreamingProfile.EncoderRCModes.BITRATE_PRIORITY);
        mProfile.setBitrateAdjustMode(mEncodingConfig.mBitrateAdjustMode);
        mProfile.setFpsControllerEnable(mEncodingConfig.mVideoFPSControl);
        mProfile.setYuvFilterMode(mEncodingConfig.mYuvFilterMode);
        if (mEncodingConfig.mBitrateAdjustMode == StreamingProfile.BitrateAdjustMode.Auto) {
            mProfile.setVideoAdaptiveBitrateRange(mEncodingConfig.mAdaptiveBitrateMin * 1024, mEncodingConfig.mAdaptiveBitrateMax * 1024);
        }
    }

    // audio quality
    if (mEncodingConfig.mIsAudioQualityPreset) {
        mProfile.setAudioQuality(mEncodingConfig.mAudioQualityPreset);
    } else {
        aProfile = new StreamingProfile.AudioProfile(
                mEncodingConfig.mAudioQualityCustomSampleRate,
                mEncodingConfig.mAudioQualityCustomBitrate * 1024
        );
    }

    // custom
    if (aProfile != null || vProfile != null) {
        StreamingProfile.AVProfile avProfile = new StreamingProfile.AVProfile(vProfile, aProfile);
        mProfile.setAVProfile(avProfile);
    }

    mProfile.setDnsManager(getMyDnsManager())
            .setStreamStatusConfig(new StreamingProfile.StreamStatusConfig(3))
            .setSendingBufferProfile(new StreamingProfile.SendingBufferProfile(0.2f, 0.8f, 3.0f, 20 * 1000));
}