LCOV - code coverage report
Current view: top level - src/zerocopy - audio_frame.cc (source / functions) Hit Total Coverage
Test: vlink Lines: 252 266 94.7 %
Date: 2026-07-26 14:05:51 Functions: 48 48 100.0 %
Branches: 128 166 77.1 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (C) 2026 by Thun Lu. All rights reserved.
       3                 :            :  * Author: Thun Lu <thun.lu@zohomail.cn>
       4                 :            :  * Repo:   https://github.com/thun-res/vlink
       5                 :            :  *  _    __   __      _           __
       6                 :            :  * | |  / /  / /     (_) ____    / /__
       7                 :            :  * | | / /  / /     / / / __ \  / //_/
       8                 :            :  * | |/ /  / /___  / / / / / / / ,<
       9                 :            :  * |___/  /_____/ /_/ /_/ /_/ /_/|_|
      10                 :            :  *
      11                 :            :  * Licensed under the Apache License, Version 2.0 (the "License");
      12                 :            :  * you may not use this file except in compliance with the License.
      13                 :            :  * You may obtain a copy of the License at
      14                 :            :  *
      15                 :            :  *     http://www.apache.org/licenses/LICENSE-2.0
      16                 :            :  *
      17                 :            :  * Unless required by applicable law or agreed to in writing, software
      18                 :            :  * distributed under the License is distributed on an "AS IS" BASIS,
      19                 :            :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      20                 :            :  * See the License for the specific language governing permissions and
      21                 :            :  * limitations under the License.
      22                 :            :  */
      23                 :            : 
      24                 :            : #include "./zerocopy/audio_frame.h"
      25                 :            : 
      26                 :            : #include <cstdint>
      27                 :            : 
      28                 :            : namespace vlink {
      29                 :            : 
      30                 :            : namespace zerocopy {
      31                 :            : 
      32                 :            : // AudioFrame
      33                 :         71 : AudioFrame::AudioFrame() noexcept {
      34                 :            : #if defined(__arm__) || defined(__x86__) || defined(__i386__)
      35                 :            : #ifndef __ANDROID__
      36                 :            : #warning "[AudioFrame] No support for 32-bit architecture."
      37                 :            : #endif
      38                 :            : #else
      39                 :            :   static_assert(sizeof(AudioFrame) == 128, "Sizeof must be 128 bytes.");
      40                 :            : #endif
      41                 :         71 : }
      42                 :            : 
      43                 :         73 : AudioFrame::~AudioFrame() noexcept {
      44   [ +  +  +  -  :         73 :   if (is_owner_ && data_ && size_ != 0) {
                   +  - ]
      45                 :         33 :     Bytes::bytes_free(data_, size_);
      46                 :            :   }
      47                 :         73 : }
      48                 :            : 
      49                 :          1 : AudioFrame::AudioFrame(const AudioFrame& target) noexcept { deep_copy(target); }
      50                 :            : 
      51                 :          1 : AudioFrame::AudioFrame(AudioFrame&& target) noexcept { move_copy(target); }
      52                 :            : 
      53                 :          1 : AudioFrame& AudioFrame::operator=(const AudioFrame& target) noexcept {
      54         [ -  + ]:          1 :   if VUNLIKELY (this == &target) {
      55                 :          0 :     return *this;
      56                 :            :   }
      57                 :            : 
      58                 :          1 :   deep_copy(target);
      59                 :            : 
      60                 :          1 :   return *this;
      61                 :            : }
      62                 :            : 
      63                 :          1 : AudioFrame& AudioFrame::operator=(AudioFrame&& target) noexcept {
      64         [ -  + ]:          1 :   if VUNLIKELY (this == &target) {
      65                 :          0 :     return *this;
      66                 :            :   }
      67                 :            : 
      68                 :          1 :   move_copy(target);
      69                 :            : 
      70                 :          1 :   return *this;
      71                 :            : }
      72                 :            : 
      73                 :         11 : bool AudioFrame::operator<<(const Bytes& bytes) noexcept {
      74                 :            :   static constexpr size_t kMagicNumberBeginSize = sizeof(kMagicNumberBegin);
      75                 :            :   static constexpr size_t kVersionSize = sizeof(kWireVersion);
      76                 :            :   // static constexpr size_t kMagicNumberEndSize = sizeof(kMagicNumberEnd);
      77                 :            : 
      78         [ +  + ]:         11 :   if VUNLIKELY (bytes.empty()) {
      79                 :          2 :     return false;
      80                 :            :   }
      81                 :            : 
      82         [ +  + ]:          9 :   if VUNLIKELY (!check_valid(bytes)) {
      83                 :          2 :     return false;
      84                 :            :   }
      85                 :            : 
      86                 :          7 :   uint32_t wire_version = 0;
      87                 :          7 :   std::memcpy(&wire_version, bytes.data() + kMagicNumberBeginSize, kVersionSize);
      88                 :            : 
      89         [ -  + ]:          7 :   if VUNLIKELY (version_major(wire_version) != version_major(kWireVersion)) {
      90                 :          0 :     return false;
      91                 :            :   }
      92                 :            : 
      93   [ +  +  +  -  :          7 :   if (is_owner_ && data_ && size_ != 0) {
                   +  - ]
      94                 :          1 :     Bytes::bytes_free(data_, size_);
      95                 :            :   }
      96                 :            : 
      97                 :            : #if defined(__GNUC__) && !defined(__clang__)
      98                 :            : #pragma GCC diagnostic push
      99                 :            : #pragma GCC diagnostic ignored "-Wclass-memaccess"
     100                 :            : #if __GNUC__ >= 11
     101                 :            : #pragma GCC diagnostic ignored "-Wstringop-overread"
     102                 :            : #endif
     103                 :            : #endif
     104                 :            : 
     105                 :          7 :   auto* target_ptr = reinterpret_cast<uint8_t*>(this);
     106                 :            : 
     107                 :          7 :   std::memcpy(target_ptr, bytes.data() + kMagicNumberBeginSize + kVersionSize, sizeof(AudioFrame));
     108                 :            : 
     109                 :            : #if defined(__GNUC__) && !defined(__clang__)
     110                 :            : #pragma GCC diagnostic pop
     111                 :            : #endif
     112                 :            : 
     113                 :          7 :   data_ = const_cast<uint8_t*>(bytes.data() + kMagicNumberBeginSize + kVersionSize + sizeof(AudioFrame));
     114                 :          7 :   is_owner_ = false;
     115                 :            : 
     116         [ +  + ]:          7 :   if VUNLIKELY (bytes.size() != get_serialized_size()) {
     117                 :          1 :     clear();
     118                 :          1 :     return false;
     119                 :            :   }
     120                 :            : 
     121                 :          6 :   return true;
     122                 :            : }
     123                 :            : 
     124                 :         10 : bool AudioFrame::operator>>(Bytes& bytes) const noexcept {
     125                 :            :   static constexpr size_t kMagicNumberBeginSize = sizeof(kMagicNumberBegin);
     126                 :            :   static constexpr size_t kVersionSize = sizeof(kWireVersion);
     127                 :            :   static constexpr size_t kMagicNumberEndSize = sizeof(kMagicNumberEnd);
     128                 :            : 
     129   [ +  +  +  +  :         10 :   if (bytes.empty() || bytes.size() != get_serialized_size()) {
                   +  + ]
     130                 :          9 :     bytes = Bytes::create(get_serialized_size());
     131                 :            : 
     132         [ -  + ]:          9 :     if VUNLIKELY (bytes.empty()) {
     133                 :          0 :       return false;
     134                 :            :     }
     135                 :            :   }
     136                 :            : 
     137                 :         10 :   std::memcpy(bytes.data(), &kMagicNumberBegin, kMagicNumberBeginSize);
     138                 :            : 
     139                 :         10 :   std::memcpy(bytes.data() + kMagicNumberBeginSize, &kWireVersion, kVersionSize);
     140                 :            : 
     141                 :            :   // NOLINTNEXTLINE(bugprone-undefined-memory-manipulation)
     142                 :         10 :   std::memcpy(bytes.data() + kMagicNumberBeginSize + kVersionSize, this, sizeof(AudioFrame));
     143                 :            : 
     144                 :         10 :   const auto data_offset = reinterpret_cast<const uint8_t*>(&data_) - reinterpret_cast<const uint8_t*>(this);
     145                 :         10 :   const size_t data_pointer_size = sizeof(data_);
     146                 :         10 :   std::memset(bytes.data() + kMagicNumberBeginSize + kVersionSize + data_offset, 0, data_pointer_size);
     147                 :            : 
     148   [ +  +  +  -  :         10 :   if VLIKELY (data_ != nullptr && size_ != 0) {
                   +  + ]
     149                 :          9 :     std::memcpy(bytes.data() + kMagicNumberBeginSize + kVersionSize + sizeof(AudioFrame), data_, size_);
     150                 :            :   }
     151                 :            : 
     152                 :         10 :   std::memcpy(bytes.data() + kMagicNumberBeginSize + kVersionSize + sizeof(AudioFrame) + size_, &kMagicNumberEnd,
     153                 :            :               kMagicNumberEndSize);
     154                 :            : 
     155                 :         10 :   return true;
     156                 :            : }
     157                 :            : 
     158                 :         16 : bool AudioFrame::check_valid(const Bytes& bytes) noexcept {
     159                 :            :   static constexpr size_t kMagicNumberBeginSize = sizeof(kMagicNumberBegin);
     160                 :            :   static constexpr size_t kVersionSize = sizeof(kWireVersion);
     161                 :            :   static constexpr size_t kMagicNumberEndSize = sizeof(kMagicNumberEnd);
     162                 :            : 
     163         [ +  + ]:         16 :   if VUNLIKELY (bytes.size() < kMagicNumberBeginSize + kVersionSize + sizeof(AudioFrame) + kMagicNumberEndSize) {
     164                 :          2 :     return false;
     165                 :            :   }
     166                 :            : 
     167                 :         14 :   uint32_t check_magic = 0;
     168                 :            : 
     169                 :         14 :   std::memcpy(&check_magic, bytes.begin(), kMagicNumberBeginSize);
     170                 :            : 
     171         [ +  + ]:         14 :   if VUNLIKELY (check_magic != kMagicNumberBegin) {
     172                 :          1 :     return false;
     173                 :            :   }
     174                 :            : 
     175                 :         13 :   uint32_t wire_version = 0;
     176                 :         13 :   std::memcpy(&wire_version, bytes.data() + kMagicNumberBeginSize, kVersionSize);
     177                 :            : 
     178         [ +  + ]:         13 :   if VUNLIKELY (version_major(wire_version) != version_major(kWireVersion)) {
     179                 :          2 :     return false;
     180                 :            :   }
     181                 :            : 
     182                 :         11 :   std::memcpy(&check_magic, bytes.end() - kMagicNumberEndSize, kMagicNumberEndSize);
     183                 :            : 
     184         [ +  + ]:         11 :   if VUNLIKELY (check_magic != kMagicNumberEnd) {
     185                 :          1 :     return false;
     186                 :            :   }
     187                 :            : 
     188                 :         10 :   return true;
     189                 :            : }
     190                 :            : 
     191                 :         23 : size_t AudioFrame::get_serialized_size() const noexcept {
     192                 :            :   static constexpr size_t kMagicNumberBeginSize = sizeof(kMagicNumberBegin);
     193                 :            :   static constexpr size_t kVersionSize = sizeof(kWireVersion);
     194                 :            :   static constexpr size_t kMagicNumberEndSize = sizeof(kMagicNumberEnd);
     195                 :            : 
     196                 :         23 :   return kMagicNumberBeginSize + kVersionSize + sizeof(AudioFrame) + size_ + kMagicNumberEndSize;
     197                 :            : }
     198                 :            : 
     199   [ +  +  +  - ]:         17 : bool AudioFrame::is_valid() const noexcept { return data_ != nullptr && size_ != 0; }
     200                 :            : 
     201                 :         10 : bool AudioFrame::shallow_copy(const AudioFrame& target) noexcept {
     202         [ +  + ]:         10 :   if VUNLIKELY (this == &target) {
     203                 :          2 :     return false;
     204                 :            :   }
     205                 :            : 
     206   [ +  +  +  -  :          8 :   if (is_owner_ && data_ && size_ != 0) {
                   +  - ]
     207                 :          1 :     const auto current = reinterpret_cast<uintptr_t>(data_);
     208                 :          1 :     const auto source = reinterpret_cast<uintptr_t>(target.data_);
     209                 :            : 
     210   [ +  -  +  -  :          1 :     if VUNLIKELY (source >= current && source - current < size_) {
                   +  - ]
     211                 :          1 :       return false;
     212                 :            :     }
     213                 :            : 
     214                 :          0 :     Bytes::bytes_free(data_, size_);
     215                 :            :   }
     216                 :            : 
     217                 :          7 :   header = target.header;
     218                 :            : 
     219                 :          7 :   update_time_ns_ = target.update_time_ns_;
     220                 :          7 :   duration_ns_ = target.duration_ns_;
     221                 :          7 :   std::memcpy(codec_, target.codec_, sizeof(codec_));
     222                 :          7 :   std::memcpy(language_, target.language_, sizeof(language_));
     223                 :          7 :   channel_ = target.channel_;
     224                 :          7 :   freq_ = target.freq_;
     225                 :          7 :   sample_rate_ = target.sample_rate_;
     226                 :          7 :   num_samples_ = target.num_samples_;
     227                 :          7 :   bitrate_ = target.bitrate_;
     228                 :          7 :   num_channels_ = target.num_channels_;
     229                 :          7 :   bit_depth_ = target.bit_depth_;
     230                 :          7 :   format_ = target.format_;
     231                 :          7 :   layout_ = target.layout_;
     232                 :          7 :   reserved_buf_ = target.reserved_buf_;
     233                 :          7 :   reserved_buf2_ = target.reserved_buf2_;
     234                 :          7 :   is_owner_ = false;
     235                 :          7 :   data_ = target.data_;
     236                 :          7 :   size_ = target.size_;
     237                 :            : 
     238                 :          7 :   return true;
     239                 :            : }
     240                 :            : 
     241                 :          6 : bool AudioFrame::deep_copy(const AudioFrame& target) noexcept {
     242   [ +  +  +  -  :          6 :   if VLIKELY (data_ && is_owner_ && target.data_ && size_ != 0 && size_ == target.size_) {
          +  +  +  -  +  
          +  +  -  +  +  
             +  -  +  + ]
     243                 :          3 :     const auto current = reinterpret_cast<uintptr_t>(data_);
     244                 :          3 :     const auto source = reinterpret_cast<uintptr_t>(target.data_);
     245                 :            : 
     246   [ +  +  +  -  :          3 :     if VUNLIKELY (source >= current && source - current < size_) {
                   +  + ]
     247                 :          2 :       return false;
     248                 :            :     }
     249                 :            : 
     250                 :          1 :     header = target.header;
     251                 :            : 
     252                 :          1 :     update_time_ns_ = target.update_time_ns_;
     253                 :          1 :     duration_ns_ = target.duration_ns_;
     254                 :          1 :     std::memcpy(codec_, target.codec_, sizeof(codec_));
     255                 :          1 :     std::memcpy(language_, target.language_, sizeof(language_));
     256                 :          1 :     channel_ = target.channel_;
     257                 :          1 :     freq_ = target.freq_;
     258                 :          1 :     sample_rate_ = target.sample_rate_;
     259                 :          1 :     num_samples_ = target.num_samples_;
     260                 :          1 :     bitrate_ = target.bitrate_;
     261                 :          1 :     num_channels_ = target.num_channels_;
     262                 :          1 :     bit_depth_ = target.bit_depth_;
     263                 :          1 :     format_ = target.format_;
     264                 :          1 :     layout_ = target.layout_;
     265                 :          1 :     reserved_buf_ = target.reserved_buf_;
     266                 :          1 :     reserved_buf2_ = target.reserved_buf2_;
     267                 :            : 
     268                 :          1 :     std::memcpy(data_, target.data_, size_);
     269                 :            : 
     270                 :          1 :     return true;
     271                 :            :   }
     272                 :            : 
     273         [ -  + ]:          3 :   if VUNLIKELY (!shallow_copy(target)) {
     274                 :          0 :     return false;
     275                 :            :   }
     276                 :            : 
     277   [ +  -  +  - ]:          3 :   if (data_ && size_ != 0) {
     278                 :          3 :     auto* target_data = data_;
     279                 :          3 :     data_ = Bytes::bytes_malloc(size_);
     280                 :            : 
     281         [ -  + ]:          3 :     if VUNLIKELY (!data_) {
     282                 :          0 :       size_ = 0;
     283                 :          0 :       return false;
     284                 :            :     }
     285                 :            : 
     286                 :          3 :     std::memcpy(data_, target_data, size_);
     287                 :          3 :     is_owner_ = true;
     288                 :            :   }
     289                 :            : 
     290                 :          3 :   return true;
     291                 :            : }
     292                 :            : 
     293                 :          4 : bool AudioFrame::move_copy(AudioFrame& target) noexcept {
     294         [ +  + ]:          4 :   if VUNLIKELY (!shallow_copy(target)) {
     295                 :          1 :     return false;
     296                 :            :   }
     297                 :            : 
     298                 :          3 :   is_owner_ = target.is_owner_;
     299                 :            : 
     300                 :          3 :   target.update_time_ns_ = 0;
     301                 :          3 :   target.duration_ns_ = 0;
     302                 :          3 :   std::memset(target.codec_, 0, sizeof(target.codec_));
     303                 :          3 :   std::memset(target.language_, 0, sizeof(target.language_));
     304                 :          3 :   target.channel_ = 0;
     305                 :          3 :   target.freq_ = 0;
     306                 :          3 :   target.sample_rate_ = 0;
     307                 :          3 :   target.num_samples_ = 0;
     308                 :          3 :   target.bitrate_ = 0;
     309                 :          3 :   target.num_channels_ = 0;
     310                 :          3 :   target.bit_depth_ = 0;
     311                 :          3 :   target.format_ = kFormatUnknown;
     312                 :          3 :   target.layout_ = kLayoutUnknown;
     313                 :          3 :   target.reserved_buf_ = 0;
     314                 :          3 :   target.reserved_buf2_ = 0;
     315                 :          3 :   target.is_owner_ = false;
     316                 :          3 :   target.data_ = nullptr;
     317                 :          3 :   target.size_ = 0;
     318                 :            : 
     319                 :            : #if defined(__GNUC__) && !defined(__clang__)
     320                 :            : #pragma GCC diagnostic push
     321                 :            : #pragma GCC diagnostic ignored "-Wclass-memaccess"
     322                 :            : #if __GNUC__ >= 11
     323                 :            : #pragma GCC diagnostic ignored "-Wstringop-overread"
     324                 :            : #endif
     325                 :            : #endif
     326                 :            : 
     327                 :          3 :   std::memset(&target.header, 0, sizeof(header));
     328                 :            : 
     329                 :            : #if defined(__GNUC__) && !defined(__clang__)
     330                 :            : #pragma GCC diagnostic pop
     331                 :            : #endif
     332                 :            : 
     333                 :          3 :   return true;
     334                 :            : }
     335                 :            : 
     336                 :         38 : bool AudioFrame::create(size_t _size) noexcept {
     337         [ +  + ]:         38 :   if VUNLIKELY (_size == 0) {
     338                 :          1 :     return false;
     339                 :            :   }
     340                 :            : 
     341   [ +  +  +  -  :         37 :   if (is_owner_ && data_ && size_ != 0) {
                   +  - ]
     342                 :          2 :     Bytes::bytes_free(data_, size_);
     343                 :            :   }
     344                 :            : 
     345                 :         37 :   data_ = Bytes::bytes_malloc(_size);
     346                 :            : 
     347         [ -  + ]:         37 :   if VUNLIKELY (!data_) {
     348                 :          0 :     size_ = 0;
     349                 :          0 :     is_owner_ = false;
     350                 :          0 :     return false;
     351                 :            :   }
     352                 :            : 
     353                 :         37 :   size_ = _size;
     354                 :         37 :   is_owner_ = true;
     355                 :            : 
     356                 :         37 :   return true;
     357                 :            : }
     358                 :            : 
     359                 :          5 : void AudioFrame::clear() noexcept {
     360   [ +  +  +  -  :          5 :   if (is_owner_ && data_ && size_ != 0) {
                   +  - ]
     361                 :          4 :     Bytes::bytes_free(data_, size_);
     362                 :            :   }
     363                 :            : 
     364                 :          5 :   update_time_ns_ = 0;
     365                 :          5 :   duration_ns_ = 0;
     366                 :          5 :   std::memset(codec_, 0, sizeof(codec_));
     367                 :          5 :   std::memset(language_, 0, sizeof(language_));
     368                 :          5 :   channel_ = 0;
     369                 :          5 :   freq_ = 0;
     370                 :          5 :   sample_rate_ = 0;
     371                 :          5 :   num_samples_ = 0;
     372                 :          5 :   bitrate_ = 0;
     373                 :          5 :   num_channels_ = 0;
     374                 :          5 :   bit_depth_ = 0;
     375                 :          5 :   format_ = kFormatUnknown;
     376                 :          5 :   layout_ = kLayoutUnknown;
     377                 :          5 :   is_owner_ = false;
     378                 :          5 :   data_ = nullptr;
     379                 :          5 :   size_ = 0;
     380                 :            : 
     381                 :            : #if defined(__GNUC__) && !defined(__clang__)
     382                 :            : #pragma GCC diagnostic push
     383                 :            : #pragma GCC diagnostic ignored "-Wclass-memaccess"
     384                 :            : #if __GNUC__ >= 11
     385                 :            : #pragma GCC diagnostic ignored "-Wstringop-overread"
     386                 :            : #endif
     387                 :            : #endif
     388                 :            : 
     389                 :          5 :   std::memset(&header, 0, sizeof(header));
     390                 :            : 
     391                 :            : #if defined(__GNUC__) && !defined(__clang__)
     392                 :            : #pragma GCC diagnostic pop
     393                 :            : #endif
     394                 :          5 : }
     395                 :            : 
     396                 :          7 : bool AudioFrame::shallow_copy(uint8_t* data, size_t size) noexcept {
     397   [ +  +  +  +  :          7 :   if VUNLIKELY (!data || size == 0) {
                   +  + ]
     398                 :          2 :     return false;
     399                 :            :   }
     400                 :            : 
     401         [ +  + ]:          5 :   if VUNLIKELY (data_ == data) {
     402                 :          1 :     return false;
     403                 :            :   }
     404                 :            : 
     405   [ +  +  +  -  :          4 :   if (is_owner_ && data_ && size_ != 0) {
                   +  - ]
     406                 :          1 :     const auto current = reinterpret_cast<uintptr_t>(data_);
     407                 :          1 :     const auto source = reinterpret_cast<uintptr_t>(data);
     408                 :            : 
     409   [ +  -  +  -  :          1 :     if VUNLIKELY (source >= current && source - current < size_) {
                   +  - ]
     410                 :          1 :       return false;
     411                 :            :     }
     412                 :            : 
     413                 :          0 :     Bytes::bytes_free(data_, size_);
     414                 :            :   }
     415                 :            : 
     416                 :          3 :   is_owner_ = false;
     417                 :            : 
     418                 :          3 :   data_ = data;
     419                 :          3 :   size_ = size;
     420                 :            : 
     421                 :          3 :   return true;
     422                 :            : }
     423                 :            : 
     424                 :          8 : bool AudioFrame::deep_copy(uint8_t* data, size_t size) noexcept {
     425   [ +  +  +  +  :          8 :   if VUNLIKELY (!data || size == 0) {
                   +  + ]
     426                 :          2 :     return false;
     427                 :            :   }
     428                 :            : 
     429         [ +  + ]:          6 :   if (is_owner_) {
     430         [ -  + ]:          4 :     if VUNLIKELY (!data_) {
     431                 :            :       return false;  // LCOV_EXCL_LINE GCOVR_EXCL_LINE
     432                 :            :     }
     433                 :            : 
     434                 :          4 :     const auto current = reinterpret_cast<uintptr_t>(data_);
     435                 :          4 :     const auto source = reinterpret_cast<uintptr_t>(data);
     436                 :            : 
     437   [ +  +  +  +  :          4 :     if VUNLIKELY (source >= current && source - current < size_) {
                   +  + ]
     438                 :          2 :       return false;
     439                 :            :     }
     440                 :            : 
     441   [ +  +  -  +  :          2 :     if VUNLIKELY (size_ != size && !create(size)) {
                   -  + ]
     442                 :          0 :       return false;
     443                 :            :     }
     444         [ -  + ]:          2 :   } else if VUNLIKELY (!create(size)) {
     445                 :          0 :     return false;
     446                 :            :   }
     447                 :            : 
     448                 :          4 :   std::memcpy(data_, data, size);
     449                 :            : 
     450                 :          4 :   return true;
     451                 :            : }
     452                 :            : 
     453                 :          2 : bool AudioFrame::fill_data(uint8_t* data, size_t size) noexcept { return deep_copy(data, size); }
     454                 :            : 
     455                 :          3 : uint64_t AudioFrame::update_time_ns() const noexcept { return update_time_ns_; }
     456                 :            : 
     457                 :          4 : uint64_t AudioFrame::duration_ns() const noexcept { return duration_ns_; }
     458                 :            : 
     459                 :         10 : std::string_view AudioFrame::codec() const noexcept { return {codec_, ::strnlen(codec_, sizeof(codec_))}; }
     460                 :            : 
     461                 :         10 : std::string_view AudioFrame::language() const noexcept { return {language_, ::strnlen(language_, sizeof(language_))}; }
     462                 :            : 
     463                 :          3 : uint32_t AudioFrame::channel() const noexcept { return channel_; }
     464                 :            : 
     465                 :          3 : uint32_t AudioFrame::freq() const noexcept { return freq_; }
     466                 :            : 
     467                 :         11 : uint32_t AudioFrame::sample_rate() const noexcept { return sample_rate_; }
     468                 :            : 
     469                 :          4 : uint32_t AudioFrame::num_samples() const noexcept { return num_samples_; }
     470                 :            : 
     471                 :          3 : uint32_t AudioFrame::bitrate() const noexcept { return bitrate_; }
     472                 :            : 
     473                 :          8 : uint16_t AudioFrame::num_channels() const noexcept { return num_channels_; }
     474                 :            : 
     475                 :          9 : uint16_t AudioFrame::bit_depth() const noexcept { return bit_depth_; }
     476                 :            : 
     477                 :         27 : AudioFrame::Format AudioFrame::format() const noexcept { return format_; }
     478                 :            : 
     479                 :          9 : AudioFrame::Layout AudioFrame::layout() const noexcept { return layout_; }
     480                 :            : 
     481                 :         41 : const uint8_t* AudioFrame::data() const noexcept { return data_; }
     482                 :            : 
     483                 :         34 : size_t AudioFrame::size() const noexcept { return size_; }
     484                 :            : 
     485                 :         23 : bool AudioFrame::is_owner() const noexcept { return is_owner_; }
     486                 :            : 
     487                 :          2 : void AudioFrame::set_update_time_ns(uint64_t update_time_ns) noexcept { update_time_ns_ = update_time_ns; }
     488                 :            : 
     489                 :          3 : void AudioFrame::set_duration_ns(uint64_t duration_ns) noexcept { duration_ns_ = duration_ns; }
     490                 :            : 
     491                 :          8 : void AudioFrame::set_codec(std::string_view codec) noexcept {
     492                 :          8 :   std::memset(codec_, 0, sizeof(codec_));
     493                 :            : 
     494                 :          8 :   size_t copy_size = codec.size();
     495                 :            : 
     496         [ +  + ]:          8 :   if (copy_size >= sizeof(codec_)) {
     497                 :          1 :     copy_size = sizeof(codec_) - 1;
     498                 :            :   }
     499                 :            : 
     500         [ +  + ]:          8 :   if VLIKELY (copy_size != 0) {
     501                 :          7 :     std::memcpy(codec_, codec.data(), copy_size);
     502                 :            :   }
     503                 :          8 : }
     504                 :            : 
     505                 :          9 : void AudioFrame::set_language(std::string_view language) noexcept {
     506                 :          9 :   std::memset(language_, 0, sizeof(language_));
     507                 :            : 
     508                 :          9 :   size_t copy_size = language.size();
     509                 :            : 
     510         [ +  + ]:          9 :   if (copy_size >= sizeof(language_)) {
     511                 :          1 :     copy_size = sizeof(language_) - 1;
     512                 :            :   }
     513                 :            : 
     514         [ +  + ]:          9 :   if VLIKELY (copy_size != 0) {
     515                 :          8 :     std::memcpy(language_, language.data(), copy_size);
     516                 :            :   }
     517                 :          9 : }
     518                 :            : 
     519                 :          2 : void AudioFrame::set_channel(uint32_t channel) noexcept { channel_ = channel; }
     520                 :            : 
     521                 :          2 : void AudioFrame::set_freq(uint32_t freq) noexcept { freq_ = freq; }
     522                 :            : 
     523                 :          8 : void AudioFrame::set_sample_rate(uint32_t sample_rate) noexcept { sample_rate_ = sample_rate; }
     524                 :            : 
     525                 :          3 : void AudioFrame::set_num_samples(uint32_t num_samples) noexcept { num_samples_ = num_samples; }
     526                 :            : 
     527                 :          2 : void AudioFrame::set_bitrate(uint32_t bitrate) noexcept { bitrate_ = bitrate; }
     528                 :            : 
     529                 :          7 : void AudioFrame::set_num_channels(uint16_t num_channels) noexcept { num_channels_ = num_channels; }
     530                 :            : 
     531                 :          5 : void AudioFrame::set_bit_depth(uint16_t bit_depth) noexcept { bit_depth_ = bit_depth; }
     532                 :            : 
     533                 :         18 : void AudioFrame::set_format(Format format) noexcept { format_ = format; }
     534                 :            : 
     535                 :          7 : void AudioFrame::set_layout(Layout layout) noexcept { layout_ = layout; }
     536                 :            : 
     537                 :            : }  // namespace zerocopy
     538                 :            : 
     539                 :            : }  // namespace vlink

Generated by: LCOV version 1.14