diff options
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/ScreenSharing/ScreenSharing.cpp | 5 | ||||
-rw-r--r-- | Swiften/ScreenSharing/VP8Decoder.cpp | 37 | ||||
-rw-r--r-- | Swiften/ScreenSharing/VP8Decoder.h | 2 | ||||
-rw-r--r-- | Swiften/ScreenSharing/VP8Encoder.cpp | 1 |
4 files changed, 39 insertions, 6 deletions
diff --git a/Swiften/ScreenSharing/ScreenSharing.cpp b/Swiften/ScreenSharing/ScreenSharing.cpp index 7fb1280..f2977a2 100644 --- a/Swiften/ScreenSharing/ScreenSharing.cpp +++ b/Swiften/ScreenSharing/ScreenSharing.cpp @@ -84,8 +84,9 @@ bool ScreenSharing::addBestCandidate(boost::shared_ptr<JingleRawUDPTransportPayl if (addr.getRawAddress().is_v6() && addr.toString().compare(2, scopeLinkBeginning.length(), scopeLinkBeginning) == 0) continue; - int port = serverSocket->bindOnAvailablePort(addr); -// int port = serverSocket->bind(HostAddressPort(addr, 29999)); + int port = serverSocket->bind(HostAddressPort(addr, 29999)); + if (port != 29999) + port = serverSocket->bindOnAvailablePort(addr); if (!port) continue; diff --git a/Swiften/ScreenSharing/VP8Decoder.cpp b/Swiften/ScreenSharing/VP8Decoder.cpp index 2634cc5..90f5101 100644 --- a/Swiften/ScreenSharing/VP8Decoder.cpp +++ b/Swiften/ScreenSharing/VP8Decoder.cpp @@ -19,7 +19,7 @@ inline int clamp8(int v) VP8Decoder::VP8Decoder() : VideoDecoder(), - codecInterface(vpx_codec_vp8_dx()), codecFlags(0) + codecInterface(vpx_codec_vp8_dx()), codecFlags(0), refFrame(0) { SWIFT_LOG(debug) << "VP8 Decoder:" << vpx_codec_iface_name(codecInterface) << std::endl; @@ -28,6 +28,11 @@ VP8Decoder::VP8Decoder() VP8Decoder::~VP8Decoder() { + vpx_codec_destroy(&codecContext); + if (refFrame) { + vpx_img_free(&refFrame->img); + delete refFrame; + } } void VP8Decoder::updateCodecConfig() @@ -53,10 +58,34 @@ void VP8Decoder::decodeFrame(const std::vector<uint8_t>& frame, int pictureID) } vpx_codec_iter_t iter = NULL; - vpx_image_t* img; - while ((img = vpx_codec_get_frame(&codecContext, &iter))) { - Image rgbImg = convertYV12toRGB(img); + vpx_image_t* decodedImg; + while ((decodedImg = vpx_codec_get_frame(&codecContext, &iter))) { + Image rgbImg = convertYV12toRGB(decodedImg); onNewImageAvailable(rgbImg); + // Restore ref from last save if corrupted, else save the ref + int corrupted = 0; + vpx_codec_control(&codecContext, VP8D_GET_FRAME_CORRUPTED, &corrupted); + if (corrupted) { + vpx_codec_control(&codecContext, VP8_SET_REFERENCE, refFrame); + } else { + // Re-alloc the image ref if the format has changed + if (refFrame && (decodedImg->d_w != refFrame->img.d_w + || decodedImg->d_h != refFrame->img.d_h + || decodedImg->fmt != refFrame->img.fmt)) { + vpx_img_free(&refFrame->img); + delete refFrame; + refFrame = 0; + } + if (!refFrame) { + refFrame = new vpx_ref_frame_t; + refFrame->frame_type = VP8_LAST_FRAME; + unsigned int align = 1; + if (decodedImg->d_w % 32 == 0) + align = 32; + vpx_img_alloc(&refFrame->img, decodedImg->fmt, decodedImg->d_w, decodedImg->d_h, align); + } + vpx_codec_control(&codecContext, VP8_COPY_REFERENCE, refFrame); + } } } diff --git a/Swiften/ScreenSharing/VP8Decoder.h b/Swiften/ScreenSharing/VP8Decoder.h index 0bdc664..0ed6334 100644 --- a/Swiften/ScreenSharing/VP8Decoder.h +++ b/Swiften/ScreenSharing/VP8Decoder.h @@ -10,6 +10,7 @@ #define VPX_CODEC_DISABLE_COMPAT 1 #include "vpx/vpx_decoder.h" +#include "vpx/vp8.h" namespace Swift { class Image; @@ -30,5 +31,6 @@ namespace Swift { vpx_codec_iface_t* codecInterface; vpx_codec_ctx_t codecContext; vpx_codec_flags_t codecFlags; + vpx_ref_frame_t* refFrame; }; } diff --git a/Swiften/ScreenSharing/VP8Encoder.cpp b/Swiften/ScreenSharing/VP8Encoder.cpp index c25e153..e48d6d9 100644 --- a/Swiften/ScreenSharing/VP8Encoder.cpp +++ b/Swiften/ScreenSharing/VP8Encoder.cpp @@ -76,6 +76,7 @@ void VP8Encoder::encodeImage(const Image& frame) vpx_enc_frame_flags_t localFrameFlags = frameFlags; if (!rpsiReceived && frameNumber > 1) { + SWIFT_LOG(error) << "VP8 Encoder: RPSI not received, do not ref last frame" << std::endl; localFrameFlags |= VP8_EFLAG_NO_REF_LAST; // VP8_EFLAG_FORCE_GF; // TODO: VP8_EFLAG_NO_REF_LAST; } |