CicadaPlayer icon indicating copy to clipboard operation
CicadaPlayer copied to clipboard

trackBitrate and bufferedPosition are always 0 for RTMP

Open isaacroldan opened this issue 5 years ago • 5 comments

Describe the bug When reproducing an RTMP stream both trackBitrate and bufferedPosition are always 0. It works as expected when reproducing HLS for instance.

To get these values i'm accessing them like this:

let bitrate = player.getCurrentTrack(CicadaTrackType(rawValue: 0))?.trackBitrate
let buffer = player.bufferedPosition

To Reproduce Steps to reproduce the behavior:

  1. Just open any RTMP stream

Expected behavior We should get the current values for bitrate and buffer as we do for HTTP streams.

Also I have one more question, is there any way to obtain bandwidth information for the current stream? Couldn't find anything in the public API.

Thanks!

isaacroldan avatar Dec 08 '20 17:12 isaacroldan

Thanks for the feedback,

I think there is no bitrate provided by CicadaPlayer except hls master playlist which have multiple bitrate.

We haven't updated the buffer position for live stream, you can modify the logic like below if you want it:

void SuperMediaPlayer::PostBufferPositionMsg()
{
    if (mPlayStatus == PLAYER_PAUSED || mPlayStatus == PLAYER_PLAYING) {
        int64_t duration;

        if (isSeeking()) {
            duration = 0;
        } else {
            duration = getPlayerBufferDuration(false, false);
        }

        if (duration >= 0) { // delete this condition
            mBufferPosition = getCurrentPosition() + duration;

            if (mEof) {
                mBufferPosition = mDuration;
            }

            mPNotifier->NotifyBufferPosition((mBufferPosition <= mDuration ? mBufferPosition : mDuration) / 1000);
        }
    }
}

But what your usecase of this ?

pingkai avatar Dec 09 '20 01:12 pingkai

Thanks for your answer!

I need to report stats of each stream and it should be consistent for all protocols, so that we can report bitrate, bandwidth and buffer position for all kind of streams.

  • Bitrate: You say then there is no way to obtain it, correct?
  • BufferPosition: Could i send a Pull Request with this change or is this something you don't want included in the project?
  • Bandwidth: Is there any way to obtain the current bandwidth used by the player?

isaacroldan avatar Dec 09 '20 11:12 isaacroldan

Is buffer duration will be better for your usecase to report, buffer position is used to display the seek bar usually, which is the reason of our logic for now.

If so, you can add a api to get the buffer duration, I think it's very easy.

The bitrate is not a fix value except a cbr video, for now, there is a value calculated by ffmpeg when call avformat_find_stream_info(), is this value satisfied for you?

If not, we need to calculate it along with the playing progress, and then, how to define the current bandwidth? The average value for a period time? Or the total average value?

pingkai avatar Dec 09 '20 13:12 pingkai

Yes, i'm looking to report buffer duration, so i guess that bufferPosition - currentPosition should do the trick.

But looking into the PostBufferPositionMsg method, if it's not being reported because of the condition you mention

if (duration >= 0) { // delete this condition

does that mean that getPlayerBufferDuration(false, false); is always 0 for RTMP? Or am I missing something?

isaacroldan avatar Dec 09 '20 17:12 isaacroldan

No, getPlayerBufferDuration get the real duration in mBufferController, I think you can get the buffer duration for all tracks, and report them, not use getPlayerBufferDuration

pingkai avatar Dec 10 '20 01:12 pingkai