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