MCPcopy Create free account
hub / github.com/apache/brpc / OnPause

Method OnPause

src/brpc/policy/rtmp_protocol.cpp:3302–3411  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3300}
3301
3302bool RtmpChunkStream::OnPause(const RtmpMessageHeader& mh,
3303 AMFInputStream* istream,
3304 Socket* socket) {
3305 if (!connection_context()->is_server_side()) {
3306 RTMP_ERROR(socket, mh) << "Client should not receive `pause'";
3307 return false;
3308 }
3309 uint32_t transaction_id = 0;
3310 if (!ReadAMFUint32(&transaction_id, istream)) {
3311 RTMP_ERROR(socket, mh) << "Fail to read pause.TransactionId";
3312 return false;
3313 }
3314 if (!ReadAMFNull(istream)) { // command object
3315 RTMP_ERROR(socket, mh) << "Fail to read pause.CommandObject";
3316 return false;
3317 }
3318 bool pause_or_unpause = true;
3319 if (!ReadAMFBool(&pause_or_unpause, istream)) {
3320 RTMP_ERROR(socket, mh) << "Fail to read pause/unpause flag";
3321 return false;
3322 }
3323 double milliseconds = 0;
3324 if (!ReadAMFNumber(&milliseconds, istream)) {
3325 RTMP_ERROR(socket, mh) << "Fail to read pause.milliSeconds";
3326 return false;
3327 }
3328
3329 butil::intrusive_ptr<RtmpStreamBase> stream;
3330 if (!connection_context()->FindMessageStream(mh.stream_id, &stream)) {
3331 RTMP_WARNING(socket, mh) << "Fail to find stream_id=" << mh.stream_id;
3332 return false;
3333 }
3334 if (stream->_paused == pause_or_unpause) {
3335 if (pause_or_unpause) {
3336 RTMP_ERROR(socket, mh) << "Pause an already paused stream";
3337 } else {
3338 RTMP_ERROR(socket, mh) << "Unpause an already unpaused stream";
3339 }
3340 return false;
3341 }
3342 int rc = static_cast<RtmpServerStream*>(stream.get())->OnPause(
3343 pause_or_unpause, milliseconds);
3344
3345 // Send back status.
3346 butil::IOBuf req_buf;
3347 {
3348 butil::IOBufAsZeroCopyOutputStream zc_stream(&req_buf);
3349 AMFOutputStream ostream(&zc_stream);
3350 if (rc == 0) {
3351 WriteAMFString(RTMP_AMF0_COMMAND_ON_STATUS, &ostream);
3352 WriteAMFUint32(0, &ostream);
3353 WriteAMFNull(&ostream);
3354 RtmpInfo info;
3355 if (pause_or_unpause) {
3356 info.set_code(RTMP_STATUS_CODE_STREAM_PAUSE);
3357 } else {
3358 info.set_code(RTMP_STATUS_CODE_STREAM_UNPAUSE);
3359 }

Callers 2

OnPlayMethod · 0.45
OnCloseStreamMethod · 0.45

Calls 15

ReadAMFUint32Function · 0.85
ReadAMFNullFunction · 0.85
ReadAMFBoolFunction · 0.85
ReadAMFNumberFunction · 0.85
WriteAMFStringFunction · 0.85
WriteAMFUint32Function · 0.85
WriteAMFNullFunction · 0.85
WriteAMFObjectFunction · 0.85
WriteAMFNumberFunction · 0.85
WriteBigEndian2BytesFunction · 0.85
WriteBigEndian4BytesFunction · 0.85
MakeUnsentControlMessageFunction · 0.85

Tested by

no test coverage detected