Remove the decoding code, just populate the av_packet. This fixes rtsp decoding because we weren't copying the decoded frame to shm raw image.
This commit is contained in:
parent
988f118ba9
commit
df7e34a51d
|
@ -170,8 +170,10 @@ int RemoteCameraRtsp::PrimeCapture() {
|
||||||
}
|
}
|
||||||
} // end foreach stream
|
} // end foreach stream
|
||||||
|
|
||||||
if ( mVideoStreamId == -1 )
|
if ( mVideoStreamId == -1 ) {
|
||||||
Fatal("Unable to locate video stream");
|
Error("Unable to locate video stream");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
if ( mAudioStreamId == -1 )
|
if ( mAudioStreamId == -1 )
|
||||||
Debug(3, "Unable to locate audio stream");
|
Debug(3, "Unable to locate audio stream");
|
||||||
|
|
||||||
|
@ -185,8 +187,10 @@ int RemoteCameraRtsp::PrimeCapture() {
|
||||||
|
|
||||||
// Find the decoder for the video stream
|
// Find the decoder for the video stream
|
||||||
AVCodec *codec = avcodec_find_decoder(mVideoCodecContext->codec_id);
|
AVCodec *codec = avcodec_find_decoder(mVideoCodecContext->codec_id);
|
||||||
if ( codec == nullptr )
|
if ( codec == nullptr ) {
|
||||||
Panic("Unable to locate codec %d decoder", mVideoCodecContext->codec_id);
|
Error("Unable to locate codec %d decoder", mVideoCodecContext->codec_id);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// Open codec
|
// Open codec
|
||||||
#if !LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 8, 0)
|
#if !LIBAVFORMAT_VERSION_CHECK(53, 8, 0, 8, 0)
|
||||||
|
@ -194,7 +198,10 @@ int RemoteCameraRtsp::PrimeCapture() {
|
||||||
#else
|
#else
|
||||||
if ( avcodec_open2(mVideoCodecContext, codec, 0) < 0 )
|
if ( avcodec_open2(mVideoCodecContext, codec, 0) < 0 )
|
||||||
#endif
|
#endif
|
||||||
Panic("Can't open codec");
|
{
|
||||||
|
Error("Can't open codec");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
|
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
|
||||||
int pSize = av_image_get_buffer_size(imagePixFormat, width, height, 1);
|
int pSize = av_image_get_buffer_size(imagePixFormat, width, height, 1);
|
||||||
|
@ -203,7 +210,8 @@ int RemoteCameraRtsp::PrimeCapture() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( (unsigned int)pSize != imagesize ) {
|
if ( (unsigned int)pSize != imagesize ) {
|
||||||
Fatal("Image size mismatch. Required: %d Available: %llu", pSize, imagesize);
|
Error("Image size mismatch. Required: %d Available: %llu", pSize, imagesize);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -222,18 +230,13 @@ int RemoteCameraRtsp::PreCapture() {
|
||||||
int RemoteCameraRtsp::Capture(std::shared_ptr<ZMPacket> &zm_packet) {
|
int RemoteCameraRtsp::Capture(std::shared_ptr<ZMPacket> &zm_packet) {
|
||||||
int frameComplete = false;
|
int frameComplete = false;
|
||||||
AVPacket *packet = &zm_packet->packet;
|
AVPacket *packet = &zm_packet->packet;
|
||||||
if ( !zm_packet->image ) {
|
|
||||||
Debug(1, "Allocating image %dx%d %d colours %d", width, height, colours, subpixelorder);
|
|
||||||
zm_packet->image = new Image(width, height, colours, subpixelorder);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
while (!frameComplete) {
|
while (!frameComplete) {
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
if (!rtspThread || rtspThread->IsStopped())
|
if (!rtspThread || rtspThread->IsStopped())
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if ( rtspThread->getFrame(buffer) ) {
|
if (rtspThread->getFrame(buffer)) {
|
||||||
Debug(3, "Read frame %d bytes", buffer.size());
|
Debug(3, "Read frame %d bytes", buffer.size());
|
||||||
Hexdump(4, buffer.head(), 16);
|
Hexdump(4, buffer.head(), 16);
|
||||||
|
|
||||||
|
@ -268,49 +271,20 @@ int RemoteCameraRtsp::Capture(std::shared_ptr<ZMPacket> &zm_packet) {
|
||||||
|
|
||||||
//while ( (!frameComplete) && (buffer.size() > 0) ) {
|
//while ( (!frameComplete) && (buffer.size() > 0) ) {
|
||||||
if ( buffer.size() > 0 ) {
|
if ( buffer.size() > 0 ) {
|
||||||
packet->data = buffer.head();
|
packet->data = (uint8_t*)av_malloc(buffer.size());
|
||||||
|
memcpy(packet->data, buffer.head(), buffer.size());
|
||||||
|
//packet->data = buffer.head();
|
||||||
packet->size = buffer.size();
|
packet->size = buffer.size();
|
||||||
bytes += packet->size;
|
bytes += packet->size;
|
||||||
|
buffer -= packet->size;
|
||||||
|
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
gettimeofday(&now, NULL);
|
gettimeofday(&now, nullptr);
|
||||||
packet->pts = packet->dts = now.tv_sec*1000000+now.tv_usec;
|
packet->pts = packet->dts = now.tv_sec*1000000+now.tv_usec;
|
||||||
|
|
||||||
int bytes_consumed = zm_packet->decode(mVideoCodecContext);
|
|
||||||
if ( bytes_consumed < 0 ) {
|
|
||||||
Error("Error while decoding frame %d", frameCount);
|
|
||||||
//Hexdump(Logger::ERROR, buffer.head(), buffer.size()>256?256:buffer.size());
|
|
||||||
}
|
|
||||||
buffer -= packet->size;
|
|
||||||
if ( bytes_consumed ) {
|
|
||||||
zm_dump_video_frame(zm_packet->in_frame, "remote_rtsp_decode");
|
|
||||||
if ( ! mVideoStream->
|
|
||||||
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
|
||||||
codecpar
|
|
||||||
#else
|
|
||||||
codec
|
|
||||||
#endif
|
|
||||||
->width ) {
|
|
||||||
zm_dump_codec(mVideoCodecContext);
|
|
||||||
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
|
||||||
zm_dump_codecpar(mVideoStream->codecpar);
|
|
||||||
mVideoStream->codecpar->width = zm_packet->in_frame->width;
|
|
||||||
mVideoStream->codecpar->height = zm_packet->in_frame->height;
|
|
||||||
#else
|
|
||||||
mVideoStream->codec->width = zm_packet->in_frame->width;
|
|
||||||
mVideoStream->codec->height = zm_packet->in_frame->height;
|
|
||||||
#endif
|
|
||||||
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
|
|
||||||
zm_dump_codecpar(mVideoStream->codecpar);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
zm_packet->codec_type = mVideoCodecContext->codec_type;
|
zm_packet->codec_type = mVideoCodecContext->codec_type;
|
||||||
zm_packet->stream = mVideoStream;
|
zm_packet->stream = mVideoStream;
|
||||||
frameComplete = true;
|
frameComplete = true;
|
||||||
Debug(2, "Frame: %d - %d/%d", frameCount, bytes_consumed, buffer.size());
|
Debug(2, "Frame: %d - %d/%d", frameCount, packet->size, buffer.size());
|
||||||
packet->data = nullptr;
|
|
||||||
packet->size = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} /* getFrame() */
|
} /* getFrame() */
|
||||||
} // end while true
|
} // end while true
|
||||||
|
|
Loading…
Reference in New Issue