| #include "api/video/i420_buffer.h" |
| 6 |
| 7 | #include "AVIOContextImpl.h" |
| 8 |
| 9 | #include <string> |
| 10 | #include <set> |
| 11 | #include <map> |
| 12 |
| 13 | namespace tgcalls { |
| 14 |
| 15 | namespace { |
| 16 |
| 17 | class MediaDataPacket { |
| 18 | public: |
| 19 | MediaDataPacket() : _packet(av_packet_alloc()) { |
| 20 | } |
| 21 |
| 22 | MediaDataPacket(MediaDataPacket &&other) : _packet(other._packet) { |
| 23 | other._packet = nullptr; |
| 24 | } |
| 25 |
| 26 | ~MediaDataPacket() { |
| 27 | if (_packet) { |
| 28 | av_packet_free(&_packet); |
| 29 | } |
| 30 | } |
| 31 |
| 32 | AVPacket *packet() { |
| 33 | return _packet; |
| 34 | } |
| 35 |
| 36 | private: |
| 37 | AVPacket *_packet = nullptr; |
| 38 | }; |
| 39 |
| 40 | class DecodableFrame { |
| 41 | public: |
| 42 | DecodableFrame(MediaDataPacket packet, int64_t pts, int64_t dts): |
| 43 | _packet(std::move(packet)), |
| 44 | _pts(pts), |
| 45 | _dts(dts) { |
| 46 | } |
| 47 |
| 48 | ~DecodableFrame() { |
| 49 | } |
| 50 |
| 51 | MediaDataPacket &packet() { |
| 52 | return _packet; |
| 53 | } |
| 54 |
| 55 | int64_t pts() { |
| 56 | return _pts; |
| 57 | } |
| 58 |
| 59 | int64_t dts() { |
| 60 | return _dts; |
| 61 | } |
| 62 |
| 63 | private: |
| 64 | MediaDataPacket _packet; |
| 65 | int64_t _pts = 0; |
| 66 | int64_t _dts = 0; |
| 67 | }; |
| 68 |
| 69 | class Frame { |
| 70 | public: |
| 71 | Frame() { |
| 72 | _frame = av_frame_alloc(); |
| 73 | } |
| 74 |
| 75 | Frame(Frame &&other) { |
| 76 | _frame = other._frame; |
| 77 | other._frame = nullptr; |
| 78 | } |
| 79 |
| 80 | ~Frame() { |
| 81 | if (_frame) { |
| 82 | av_frame_unref(_frame); |
| 83 | } |
| 84 | } |
| 85 |
| 86 | AVFrame *frame() { |
| 87 | return _frame; |
| 88 | } |
| 89 |
| 90 | double pts(AVStream *stream) { |
| 91 | int64_t framePts = _frame->pts; |
| 92 | double spf = av_q2d(stream->time_base); |
| 93 | return ((double)framePts) * spf; |
| 94 | } |
| 95 |
| 96 | double duration(AVStream *stream) { |
| 97 | int64_t frameDuration = _frame->pkt_duration; |
| 98 | double spf = av_q2d(stream->time_base); |
| 99 | if (frameDuration != 0) { |
| 100 | return ((double)frameDuration) * spf; |
| 101 | } else { |
| 102 | return spf; |
| 103 | } |
| 104 | } |
| 105 |
| 106 | private: |
| 107 | AVFrame *_frame = nullptr; |
| 108 | }; |
| 109 |
| 110 | struct VideoStreamEvent { |
| 111 | int32_t offset = 0; |
| 112 | std::string endpointId; |
| 113 | int32_t rotation = 0; |
| 114 | int32_t extra = 0; |
| 115 | }; |
| 116 |
| 117 | struct VideoStreamInfo { |
| 118 | std::string container; |
| 119 | int32_t activeMask = 0; |
| 120 | std::vector<VideoStreamEvent> events; |
| 121 | }; |
| 122 |
| 123 | absl::optional<int32_t> readInt32(std::vector<uint8_t> const &data, int &offset) { |
| 124 | if (offset + 4 > data.size()) { |
| 125 | return absl::nullopt; |
| 126 | } |
| 127 |
| 128 | int32_t value = 0; |
| 129 | memcpy(&value, data.data() + offset, 4); |
| 130 | offset += 4; |
| 131 |
| 132 | return value; |
| 133 | } |
| 134 |
| 135 | absl::optional<uint8_t> readBytesAsInt32(std::vector<uint8_t> const &data, int &offset, int count) { |
| 136 | if (offset + count > data.size()) { |
| 137 | return absl::nullopt; |
| 138 | } |
| 139 |
| 140 | if (count == 0) { |
| 141 | return absl::nullopt; |
| 142 | } |
| 143 |
| 144 | if (count <= 4) { |
| 145 | int32_t value = 0; |
| 146 | memcpy(&value, data.data() + offset, count); |
| 147 | offset += count; |
| 148 | return value; |
| 149 | } else { |
| 150 | return absl::nullopt; |
| 151 | } |
| 152 | } |
| 153 |
| 154 | int32_t roundUp(int32_t numToRound, int32_t multiple) { |
| 155 | if (multiple == 0) { |
| 156 | return numToRound; |
| 157 | } |
| 158 |
| 159 | int32_t remainder = numToRound % multiple; |
| 160 | if (remainder == 0) { |
| 161 | return numToRound; |
| 162 | } |
| 163 |
| 164 | return numToRound + multiple - remainder; |
| 165 | } |
| 166 |
| 167 | absl::optional<std::string> readSerializedString(std::vector<uint8_t> const &data, int &offset) { |
| 168 | if (const auto tmp = readBytesAsInt32(data, offset, 1)) { |
| 169 | int paddingBytes = 0; |
| 170 | int length = 0; |
| 171 | if (tmp.value() == 254) { |
| 172 | if (const auto len = readBytesAsInt32(data, offset, 3)) { |
| 173 | length = len.value(); |
| 174 | paddingBytes = roundUp(length, 4) - length; |
| 175 | } else { |
| 176 | return absl::nullopt; |
| 177 | } |
| 178 | } |
| 179 | else { |
| 180 | length = tmp.value(); |
| 181 | paddingBytes = roundUp(length + 1, 4) - (length + 1); |
| 182 | } |
| 183 |
| 184 | if (offset + length > data.size()) { |
| 185 | return absl::nullopt; |
| 186 | } |
| 187 |
| 188 | std::string result(data.data() + offset, data.data() + offset + length); |
| 189 |
| 190 | offset += length; |
| 191 | offset += paddingBytes; |
| 192 |
| 193 | return result; |
| 194 | } else { |
| 195 | return absl::nullopt; |
| 196 | } |
| 197 | } |
| 198 |
| 199 | absl::optional<VideoStreamEvent> readVideoStreamEvent(std::vector<uint8_t> const &data, int &offset) { |
| 200 | VideoStreamEvent event; |
| 201 |
| 202 | if (const auto offsetValue = readInt32(data, offset)) { |
| 203 | event.offset = offsetValue.value(); |
| 204 | } else { |
| 205 | return absl::nullopt; |
| 206 | } |
| 207 |
| 208 | if (const auto endpointId = readSerializedString(data, offset)) { |
| 209 | event.endpointId = endpointId.value(); |
| 210 | } else { |
| 211 | return absl::nullopt; |
| 212 | } |
| 213 |
| 214 | if (const auto rotation = readInt32(data, offset)) { |
| 215 | event.rotation = rotation.value(); |
| 216 | } else { |
| 217 | return absl::nullopt; |
| 218 | } |
| 219 |
| 220 | if (const auto extra = readInt32(data, offset)) { |
| 221 | event.extra = extra.value(); |
| 222 | } else { |
| 223 | return absl::nullopt; |
| 224 | } |
| 225 |
| 226 | return event; |
| 227 | } |
| 228 |
| 229 | absl::optional<VideoStreamInfo> consumeVideoStreamInfo(std::vector<uint8_t> &data) { |
| 230 | int offset = 0; |
| 231 | if (const auto signature = readInt32(data, offset)) { |
| 232 | if (signature.value() != 0xa12e810d) { |
| 233 | return absl::nullopt; |
| 234 | } |
| 235 | } else { |
| 236 | return absl::nullopt; |
| 237 | } |
| 238 |
| 239 | VideoStreamInfo info; |
| 240 |
| 241 | if (const auto container = readSerializedString(data, offset)) { |
| 242 | info.container = container.value(); |
| 243 | } else { |
| 244 | return absl::nullopt; |
| 245 | } |
| 246 |
| 247 | if (const auto activeMask = readInt32(data, offset)) { |
| 248 | info.activeMask = activeMask.value(); |
| 249 | } else { |
| 250 | return absl::nullopt; |
| 251 | } |
| 252 |
| 253 | if (const auto eventCount = readInt32(data, offset)) { |
| 254 | if (eventCount > 0) { |
| 255 | if (const auto event = readVideoStreamEvent(data, offset)) { |
| 256 | info.events.push_back(event.value()); |
| 257 | } else { |
| 258 | return absl::nullopt; |
| 259 | } |
| 260 | } else { |
| 261 | return absl::nullopt; |
| 262 | } |
| 263 | } else { |
| 264 | return absl::nullopt; |
| 265 | } |
| 266 |
| 267 | data.erase(data.begin(), data.begin() + offset); |
| 268 |
| 269 | return info; |
| 270 | } |
| 271 |
| 272 | } |
| 273 |
| 274 | class VideoStreamingPartInternal { |
| 275 | public: |
| 276 | VideoStreamingPartInternal(std::string endpointId, webrtc::VideoRotation rotation, std::vector<uint8_t> &&fileData, std::string const &container) : |
| 277 | _endpointId(endpointId), |
| 278 | _rotation(rotation) { |
| 279 | _avIoContext = std::make_unique<AVIOContextImpl>(std::move(fileData)); |
| 280 |
| 281 | int ret = 0; |
| 282 |
| 283 | AVInputFormat *inputFormat = av_find_input_format(container.c_str()); |
| 284 | if (!inputFormat) { |
| 285 | _didReadToEnd = true; |
| 286 | return; |
| 287 | } |
| 288 |
| 289 | _inputFormatContext = avformat_alloc_context(); |
| 290 | if (!_inputFormatContext) { |
| 291 | _didReadToEnd = true; |
| 292 | return; |
| 293 | } |
| 294 |
| 295 | _inputFormatContext->pb = _avIoContext->getContext(); |
| 296 |
| 297 | if ((ret = avformat_open_input(&_inputFormatContext, "", inputFormat, nullptr)) < 0) { |
| 298 | _didReadToEnd = true; |
| 299 | return; |
| 300 | } |
| 301 |
| 302 | if ((ret = avformat_find_stream_info(_inputFormatContext, nullptr)) < 0) { |
| 303 | _didReadToEnd = true; |
| 304 |
| 305 | avformat_close_input(&_inputFormatContext); |
| 306 | _inputFormatContext = nullptr; |
| 307 | return; |
| 308 | } |
| 309 |
| 310 | AVCodecParameters *videoCodecParameters = nullptr; |
| 311 | AVStream *videoStream = nullptr; |
| 312 | for (int i = 0; i < _inputFormatContext->nb_streams; i++) { |
| 313 | AVStream *inStream = _inputFormatContext->streams[i]; |
| 314 |
| 315 | AVCodecParameters *inCodecpar = inStream->codecpar; |
| 316 | if (inCodecpar->codec_type != AVMEDIA_TYPE_VIDEO) { |
| 317 | continue; |
| 318 | } |
| 319 | videoCodecParameters = inCodecpar; |
| 320 | videoStream = inStream; |
| 321 |
| 322 | break; |
| 323 | } |
| 324 |
| 325 | if (videoCodecParameters && videoStream) { |
| 326 | AVCodec *codec = avcodec_find_decoder(videoCodecParameters->codec_id); |
| 327 | if (codec) { |
| 328 | _codecContext = avcodec_alloc_context3(codec); |
| 329 | ret = avcodec_parameters_to_context(_codecContext, videoCodecParameters); |
| 330 | if (ret < 0) { |
| 331 | _didReadToEnd = true; |
| 332 |
| 333 | avcodec_free_context(&_codecContext); |
| 334 | _codecContext = nullptr; |
| 335 | } else { |
| 336 | _codecContext->pkt_timebase = videoStream->time_base; |
| 337 |
| 338 | ret = avcodec_open2(_codecContext, codec, nullptr); |
| 339 | if (ret < 0) { |
| 340 | _didReadToEnd = true; |
| 341 |
| 342 | avcodec_free_context(&_codecContext); |
| 343 | _codecContext = nullptr; |
| 344 | } else { |
| 345 | _videoStream = videoStream; |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 |
| 352 | ~VideoStreamingPartInternal() { |
| 353 | if (_codecContext) { |
| 354 | avcodec_close(_codecContext); |
| 355 | avcodec_free_context(&_codecContext); |
| 356 | } |
| 357 | if (_inputFormatContext) { |
| 358 | avformat_close_input(&_inputFormatContext); |
| 359 | } |
| 360 | } |
| 361 |
| 362 | std::string endpointId() { |
| 363 | return _endpointId; |
| 364 | } |
| 365 |
| 366 | absl::optional<MediaDataPacket> readPacket() { |
| 367 | if (_didReadToEnd) { |
| 368 | return absl::nullopt; |
| 369 | } |
| 370 | if (!_inputFormatContext) { |
| 371 | return absl::nullopt; |
| 372 | } |
| 373 |
| 374 | MediaDataPacket packet; |
| 375 | int result = av_read_frame(_inputFormatContext, packet.packet()); |
| 376 | if (result < 0) { |
| 377 | return absl::nullopt; |
| 378 | } |
| 379 |
| 380 | return packet; |
| 381 | } |
| 382 |
| 383 | std::shared_ptr<DecodableFrame> readNextDecodableFrame() { |
| 384 | while (true) { |
| 385 | absl::optional<MediaDataPacket> packet = readPacket(); |
| 386 | if (packet) { |
| 387 | if (_videoStream && packet->packet()->stream_index == _videoStream->index) { |
| 388 | return std::make_shared<DecodableFrame>(std::move(packet.value()), packet->packet()->pts, packet->packet()->dts); |
| 389 | } |
| 390 | } else { |
| 391 | return nullptr; |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 |
| 396 | absl::optional<VideoStreamingPartFrame> convertCurrentFrame() { |
| 397 | rtc::scoped_refptr<webrtc::I420Buffer> i420Buffer = webrtc::I420Buffer::Copy( |
| 398 | _frame.frame()->width, |
| 399 | _frame.frame()->height, |
| 400 | _frame.frame()->data[0], |
| 401 | _frame.frame()->linesize[0], |
| 402 | _frame.frame()->data[1], |
| 403 | _frame.frame()->linesize[1], |
| 404 | _frame.frame()->data[2], |
| 405 | _frame.frame()->linesize[2] |
| 406 | ); |
| 407 | if (i420Buffer) { |
| 408 | auto videoFrame = webrtc::VideoFrame::Builder() |
| 409 | .set_video_frame_buffer(i420Buffer) |
| 410 | .set_rotation(_rotation) |
| 411 | .build(); |
| 412 |
| 413 | return VideoStreamingPartFrame(_endpointId, videoFrame, _frame.pts(_videoStream), _frame.duration(_videoStream), _frameIndex); |
| 414 | } else { |
| 415 | return absl::nullopt; |
| 416 | } |
| 417 | } |
| 418 |
| 419 | absl::optional<VideoStreamingPartFrame> getNextFrame() { |
| 420 | if (!_codecContext) { |
| 421 | return {}; |
| 422 | } |
| 423 |
| 424 | while (true) { |
| 425 | if (_didReadToEnd) { |
| 426 | if (!_finalFrames.empty()) { |
| 427 | auto frame = _finalFrames[0]; |
| 428 | _finalFrames.erase(_finalFrames.begin()); |
| 429 | return frame; |
| 430 | } else { |
| 431 | break; |
| 432 | } |
| 433 | } else { |
| 434 | const auto frame = readNextDecodableFrame(); |
| 435 | if (frame) { |
| 436 | auto status = avcodec_send_packet(_codecContext, frame->packet().packet()); |
| 437 | if (status == 0) { |
| 438 | auto status = avcodec_receive_frame(_codecContext, _frame.frame()); |
| 439 | if (status == 0) { |
| 440 | auto convertedFrame = convertCurrentFrame(); |
| 441 | if (convertedFrame) { |
| 442 | _frameIndex++; |
| 443 | return convertedFrame; |
| 444 | } |
| 445 | } else if (status == AVERROR(EAGAIN)) { |
| 446 | // more data needed |
| 447 | } else { |
| 448 | _didReadToEnd = true; |
| 449 | break; |
| 450 | } |
| 451 | } else { |
| 452 | _didReadToEnd = true; |
| 453 | return {}; |
| 454 | } |
| 455 | } else { |
| 456 | _didReadToEnd = true; |
| 457 | int status = avcodec_send_packet(_codecContext, nullptr); |
| 458 | if (status == 0) { |
| 459 | while (true) { |
| 460 | auto status = avcodec_receive_frame(_codecContext, _frame.frame()); |
| 461 | if (status == 0) { |
| 462 | auto convertedFrame = convertCurrentFrame(); |
| 463 | if (convertedFrame) { |
| 464 | _frameIndex++; |
| 465 | _finalFrames.push_back(convertedFrame.value()); |
| 466 | } |
| 467 | } else { |
| 468 | break; |
| 469 | } |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 |
| 476 | return {}; |
| 477 | } |
| 478 |
| 479 | private: |
| 480 | std::string _endpointId; |
| 481 | webrtc::VideoRotation _rotation = webrtc::VideoRotation::kVideoRotation_0; |
| 482 |
| 483 | std::unique_ptr<AVIOContextImpl> _avIoContext; |
| 484 |
| 485 | AVFormatContext *_inputFormatContext = nullptr; |
| 486 | AVCodecContext *_codecContext = nullptr; |
| 487 | AVStream *_videoStream = nullptr; |
| 488 | Frame _frame; |
| 489 |
| 490 | std::vector<VideoStreamingPartFrame> _finalFrames; |
| 491 |
| 492 | int _frameIndex = 0; |
| 493 | bool _didReadToEnd = false; |
| 494 | }; |
| 495 |
| 496 | class VideoStreamingPartState { |
| 497 | public: |
| 498 | VideoStreamingPartState(std::vector<uint8_t> &&data, VideoStreamingPart::ContentType contentType) { |
| 499 | _videoStreamInfo = consumeVideoStreamInfo(data); |
| 500 | if (!_videoStreamInfo) { |
| 501 | return; |
| 502 | } |
| 503 |
| 504 | for (size_t i = 0; i < _videoStreamInfo->events.size(); i++) { |
| 505 | if (_videoStreamInfo->events[i].offset < 0) { |
| 506 | continue; |
| 507 | } |
| 508 | size_t endOffset = 0; |
| 509 | if (i == _videoStreamInfo->events.size() - 1) { |
| 510 | endOffset = data.size(); |
| 511 | } else { |
| 512 | endOffset = _videoStreamInfo->events[i + 1].offset; |
| 513 | } |
| 514 | if (endOffset <= _videoStreamInfo->events[i].offset) { |
| 515 | continue; |
| 516 | } |
| 517 | if (endOffset > data.size()) { |
| 518 | continue; |
| 519 | } |
| 520 | std::vector<uint8_t> dataSlice(data.begin() + _videoStreamInfo->events[i].offset, data.begin() + endOffset); |
| 521 | webrtc::VideoRotation rotation = webrtc::VideoRotation::kVideoRotation_0; |
| 522 | switch (_videoStreamInfo->events[i].rotation) { |
| 523 | case 0: { |
| 524 | rotation = webrtc::VideoRotation::kVideoRotation_0; |
| 525 | break; |
| 526 | } |
| 527 | case 90: { |
| 528 | rotation = webrtc::VideoRotation::kVideoRotation_90; |
| 529 | break; |
| 530 | } |
| 531 | case 180: { |
| 532 | rotation = webrtc::VideoRotation::kVideoRotation_180; |
| 533 | break; |
| 534 | } |
| 535 | case 270: { |
| 536 | rotation = webrtc::VideoRotation::kVideoRotation_270; |
| 537 | break; |
| 538 | } |
| 539 | default: { |
| 540 | break; |
| 541 | } |
| 542 | } |
| 543 |
| 544 | switch (contentType) { |
| 545 | case VideoStreamingPart::ContentType::Audio: { |
| 546 | auto part = std::make_unique<AudioStreamingPart>(std::move(dataSlice), _videoStreamInfo->container, true); |
| 547 | _parsedAudioParts.push_back(std::move(part)); |
| 548 |
| 549 | break; |
| 550 | } |
| 551 | case VideoStreamingPart::ContentType::Video: { |
| 552 | auto part = std::make_unique<VideoStreamingPartInternal>(_videoStreamInfo->events[i].endpointId, rotation, std::move(dataSlice), _videoStreamInfo->container); |
| 553 | _parsedVideoParts.push_back(std::move(part)); |
| 554 |
| 555 | break; |
| 556 | } |
| 557 | default: { |
| 558 | break; |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 |
| 564 | ~VideoStreamingPartState() { |
| 565 | } |
| 566 |
| 567 | absl::optional<VideoStreamingPartFrame> getFrameAtRelativeTimestamp(double timestamp) { |
| 568 | while (true) { |
| 569 | if (!_currentFrame) { |
| 570 | if (!_parsedVideoParts.empty()) { |
| 571 | auto result = _parsedVideoParts[0]->getNextFrame(); |
| 572 | if (result) { |
| 573 | _currentFrame = result; |
| 574 | _relativeTimestamp += result->duration; |
| 575 | } else { |
| 576 | _parsedVideoParts.erase(_parsedVideoParts.begin()); |
| 577 | continue; |
| 578 | } |
| 579 | } |
| 580 | } |
| 581 |
| 582 | if (_currentFrame) { |
| 583 | if (timestamp <= _relativeTimestamp) { |
| 584 | return _currentFrame; |
| 585 | } else { |
| 586 | _currentFrame = absl::nullopt; |
| 587 | } |
| 588 | } else { |
| 589 | return absl::nullopt; |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 |
| 594 | absl::optional<std::string> getActiveEndpointId() const { |
| 595 | if (!_parsedVideoParts.empty()) { |
| 596 | return _parsedVideoParts[0]->endpointId(); |
| 597 | } else { |
| 598 | return absl::nullopt; |
| 599 | } |
| 600 | } |
| 601 |
| 602 | int getAudioRemainingMilliseconds() { |
| 603 | while (!_parsedAudioParts.empty()) { |
| 604 | auto firstPartResult = _parsedAudioParts[0]->getRemainingMilliseconds(); |
| 605 | if (firstPartResult <= 0) { |
| 606 | _parsedAudioParts.erase(_parsedAudioParts.begin()); |
| 607 | } else { |
| 608 | return firstPartResult; |
| 609 | } |
| 610 | } |
| 611 | return 0; |
| 612 | } |
| 613 |
| 614 | std::vector<AudioStreamingPart::StreamingPartChannel> getAudio10msPerChannel(AudioStreamingPartPersistentDecoder &persistentDecoder) { |
| 615 | while (!_parsedAudioParts.empty()) { |
| 616 | auto firstPartResult = _parsedAudioParts[0]->get10msPerChannel(persistentDecoder); |
| 617 | if (firstPartResult.empty()) { |
| 618 | _parsedAudioParts.erase(_parsedAudioParts.begin()); |
| 619 | } else { |
| 620 | return firstPartResult; |
| 621 | } |
| 622 | } |
| 623 | return {}; |
| 624 | } |
| 625 |
| 626 | private: |
| 627 | absl::optional<VideoStreamInfo> _videoStreamInfo; |
| 628 | std::vector<std::unique_ptr<VideoStreamingPartInternal>> _parsedVideoParts; |
| 629 | absl::optional<VideoStreamingPartFrame> _currentFrame; |
| 630 | double _relativeTimestamp = 0.0; |
| 631 |
| 632 | std::vector<std::unique_ptr<AudioStreamingPart>> _parsedAudioParts; |
| 633 | }; |
| 634 |
| 635 | VideoStreamingPart::VideoStreamingPart(std::vector<uint8_t> &&data, VideoStreamingPart::ContentType contentType) { |
| 636 | if (!data.empty()) { |
| 637 | _state = new VideoStreamingPartState(std::move(data), contentType); |
| 638 | } |
| 639 | } |
| 640 |
| 641 | VideoStreamingPart::~VideoStreamingPart() { |
| 642 | if (_state) { |
| 643 | delete _state; |
| 644 | } |
| 645 | } |
| 646 |
| 647 | absl::optional<VideoStreamingPartFrame> VideoStreamingPart::getFrameAtRelativeTimestamp(double timestamp) { |
| 648 | return _state |
| 649 | ? _state->getFrameAtRelativeTimestamp(timestamp) |
| 650 | : absl::nullopt; |
| 651 | } |
| 652 |
| 653 | absl::optional<std::string> VideoStreamingPart::getActiveEndpointId() const { |
| 654 | return _state |
| 655 | ? _state->getActiveEndpointId() |
| 656 | : absl::nullopt; |
| 657 | } |
| 658 |
| 659 | int VideoStreamingPart::getAudioRemainingMilliseconds() { |
| 660 | return _state |
| 661 | ? _state->getAudioRemainingMilliseconds() |
| 662 | : 0; |
| 663 | } |
| 664 | std::vector<AudioStreamingPart::StreamingPartChannel> VideoStreamingPart::getAudio10msPerChannel(AudioStreamingPartPersistentDecoder &persistentDecoder) { |
| 665 | return _state |
| 666 | ? _state->getAudio10msPerChannel(persistentDecoder) |
| 667 | : std::vector<AudioStreamingPart::StreamingPartChannel>(); |
| 668 | } |
| 669 |
| 670 | } |
| 671 |