QByteArray Frame::data(int plane) const { if (plane < 0 || plane >= planeCount()) { qWarning("Invalid plane! Valid range is [0, %d)", planeCount()); return QByteArray(); } return QByteArray((char*)d_func()->planes[plane], bytesPerLine(plane)); }
const uchar* Frame::bits(int plane) const { if (plane < 0 || plane >= planeCount()) { qWarning("Invalid plane! Valid range is [0, %d)", planeCount()); return 0; } return d_func()->planes[plane]; }
int Frame::bytesPerLine(int plane) const { if (plane < 0 || plane >= planeCount()) { qWarning("Invalid plane! Valid range is [0, %d)", planeCount()); return 0; } return d_func()->line_sizes[plane]; }
void* VideoFrame::createInteropHandle(void* handle, SurfaceType type, int plane) { Q_D(VideoFrame); const QVariant v = d->metadata.value(QStringLiteral("surface_interop")); if (!v.isValid()) return 0; d->surface_interop = v.value<VideoSurfaceInteropPtr>(); if (!d->surface_interop) return 0; if (plane > planeCount()) return 0; return d->surface_interop->createHandle(handle, type, format(), plane, planeWidth(plane), planeHeight(plane)); }
void *VideoFrame::map(SurfaceType type, void *handle, int plane) { Q_D(VideoFrame); const QVariant v = d->metadata.value(QStringLiteral("surface_interop")); if (!v.isValid()) return 0; d->surface_interop = v.value<VideoSurfaceInteropPtr>(); if (!d->surface_interop) return 0; if (plane > planeCount()) return 0; return d->surface_interop->map(type, format(), handle, plane); }
AudioFrame AudioFrame::clone() const { Q_D(const AudioFrame); if (d->format.sampleFormatFFmpeg() == AV_SAMPLE_FMT_NONE || d->format.channels() <= 0) return AudioFrame(); if (d->samples_per_ch <= 0 || bytesPerLine(0) <= 0) return AudioFrame(format()); QByteArray buf(bytesPerLine()*planeCount(), 0); AudioFrame f(buf, d->format); f.setSamplesPerChannel(samplesPerChannel()); char *dst = buf.data(); //must before buf is shared, otherwise data will be detached. for (int i = 0; i < f.planeCount(); ++i) { const int plane_size = f.bytesPerLine(i); memcpy(dst, f.constBits(i), plane_size); dst += plane_size; } f.setTimestamp(timestamp()); // meta data? return f; }
void Frame::setBits(quint8 *slice[]) { for (int i = 0; i < planeCount(); ++i ) { setBits(slice[i], i); } }
void Frame::setBytesPerLine(int stride[]) { for (int i = 0; i < planeCount(); ++i ) { setBytesPerLine(stride[i], i); } }