| 106 | } |
| 107 | |
| 108 | bool H264HwDecoder::begin(fl::filebuf_ptr stream) FL_NOEXCEPT { |
| 109 | if (!stream) { |
| 110 | mImpl->error = true; |
| 111 | mImpl->errorMsg = "Null stream"; |
| 112 | return false; |
| 113 | } |
| 114 | mImpl->stream = stream; |
| 115 | |
| 116 | // Read all data from stream |
| 117 | fl::size total = stream->size(); |
| 118 | if (total == 0) { |
| 119 | fl::u8 buf[1024]; |
| 120 | while (true) { |
| 121 | fl::size n = stream->read(buf, sizeof(buf)); |
| 122 | if (n == 0) break; |
| 123 | for (fl::size i = 0; i < n; i++) { |
| 124 | mImpl->mp4Data.push_back(buf[i]); |
| 125 | } |
| 126 | } |
| 127 | } else { |
| 128 | mImpl->mp4Data.resize(total); |
| 129 | stream->read(mImpl->mp4Data.data(), total); |
| 130 | } |
| 131 | |
| 132 | if (mImpl->mp4Data.empty()) { |
| 133 | mImpl->error = true; |
| 134 | mImpl->errorMsg = "No data read from stream"; |
| 135 | return false; |
| 136 | } |
| 137 | |
| 138 | // Parse MP4 container |
| 139 | fl::string parseError; |
| 140 | mImpl->track = parseMp4(mImpl->mp4Data, &parseError); |
| 141 | if (!mImpl->track.isValid) { |
| 142 | mImpl->error = true; |
| 143 | mImpl->errorMsg = "MP4 parse failed: "; |
| 144 | mImpl->errorMsg += parseError; |
| 145 | return false; |
| 146 | } |
| 147 | |
| 148 | // Parse H264 info for dimensions |
| 149 | mImpl->info = H264::parseH264Info(mImpl->mp4Data, &parseError); |
| 150 | if (!mImpl->info.isValid) { |
| 151 | mImpl->error = true; |
| 152 | mImpl->errorMsg = "H264 info parse failed: "; |
| 153 | mImpl->errorMsg += parseError; |
| 154 | return false; |
| 155 | } |
| 156 | |
| 157 | // Extract Annex B NAL units |
| 158 | mImpl->annexB = extractH264NalUnits(mImpl->mp4Data, mImpl->track, &parseError); |
| 159 | if (mImpl->annexB.empty()) { |
| 160 | mImpl->error = true; |
| 161 | mImpl->errorMsg = "No NAL units extracted: "; |
| 162 | mImpl->errorMsg += parseError; |
| 163 | return false; |
| 164 | } |
| 165 |
no test coverage detected