Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix high quality video sending. #629

Closed

Conversation

zoff99
Copy link

@zoff99 zoff99 commented Dec 4, 2017

This change is Reviewable

@CLAassistant
Copy link

CLAassistant commented Dec 4, 2017

CLA assistant check
All committers have signed the CLA.

@zoff99 zoff99 mentioned this pull request Dec 4, 2017
@zoff99
Copy link
Author

zoff99 commented Dec 4, 2017

it would be good that this gets tested first, to see if this solution does actually work as intended

@SkyzohKey SkyzohKey added CAT:code_cleanup toxav Audio/video P2 Medium priority labels Dec 4, 2017
@nurupo
Copy link
Member

nurupo commented Dec 4, 2017

The compiler complains about some things.

For example

/home/travis/build/TokTok/c-toxcore/toxav/toxav.c:883:52: error: signed shift result (0x80000000) sets the sign bit of the shift expression's type ('int') and becomes negative [-Werror,-Wshift-sign-overflow]
                        frame_length_in_bytes = (1 << 31) | LOWER_31_BITS(frame_length_in_bytes);
                                                 ~ ^  ~~

1 << 31 is an undefined behaviour in C and C++ as 2^31 is unrepresentative in int which maximum value is 2^31-1. It overflows and signed integer overflow is an undefined behaviour. You might want to cast it to unsigned int, or better yet uint32_t because int isn't always 32-bit or larger, it can be 16-bit, as defined by the C standard.

Undefined behaviour is very bad and it allows the compiler to pretty much treat the code as if it will never be reached and optimize it with this in mind, which can result in very bizarre optimizations. I would suggest fixing the errors first before testing the PR, as they might affect your testing.

@zoff99
Copy link
Author

zoff99 commented Dec 4, 2017

@nurupo what compiler flags are you using? what are the minimum flags to use?

@zoff99
Copy link
Author

zoff99 commented Dec 4, 2017

also, has anybody ever used toxcore on big-endian? i am not sure that all the already existing code is endianness safe

@robinlinden
Copy link
Member

The default ones on CMake:

c-toxcore/CMakeLists.txt

Lines 53 to 112 in 0fce3fc

add_cflag("-std=c99")
add_cxxflag("-std=c++11")
# Warn on non-ISO C.
add_cflag("-pedantic")
option(WARNINGS "Enable additional compiler warnings" ON)
if(WARNINGS)
# Add all warning flags we can.
add_flag("-Wall")
add_flag("-Wextra")
add_flag("-Weverything")
# Disable specific warning flags for both C and C++.
add_flag("-Wno-cast-align")
add_flag("-Wno-conversion")
add_flag("-Wno-covered-switch-default")
# Due to clang's tolower() macro being recursive https://github.com/TokTok/c-toxcore/pull/481
add_flag("-Wno-disabled-macro-expansion")
add_flag("-Wno-documentation-deprecated-sync")
add_flag("-Wno-format-nonliteral")
add_flag("-Wno-missing-field-initializers")
add_flag("-Wno-missing-prototypes")
add_flag("-Wno-padded")
add_flag("-Wno-parentheses")
add_flag("-Wno-return-type")
add_flag("-Wno-sign-compare")
add_flag("-Wno-sign-conversion")
add_flag("-Wno-tautological-constant-out-of-range-compare")
# Our use of mutexes results in a false positive, see 1bbe446
add_flag("-Wno-thread-safety-analysis")
add_flag("-Wno-type-limits")
add_flag("-Wno-undef")
add_flag("-Wno-unreachable-code")
add_flag("-Wno-unused-macros")
add_flag("-Wno-unused-parameter")
add_flag("-Wno-vla")
# Disable specific warning flags for C.
add_cflag("-Wno-assign-enum")
add_cflag("-Wno-bad-function-cast")
add_cflag("-Wno-double-promotion")
add_cflag("-Wno-gnu-zero-variadic-macro-arguments")
add_cflag("-Wno-packed")
add_cflag("-Wno-reserved-id-macro")
add_cflag("-Wno-shadow")
add_cflag("-Wno-shorten-64-to-32")
add_cflag("-Wno-unreachable-code-return")
add_cflag("-Wno-unused-but-set-variable")
add_cflag("-Wno-used-but-marked-unused")
# Disable specific warning flags for C++.
add_cxxflag("-Wno-c++11-compat")
add_cxxflag("-Wno-c++11-extensions")
add_cxxflag("-Wno-c++11-narrowing")
add_cxxflag("-Wno-c99-extensions")
add_cxxflag("-Wno-narrowing")
add_cxxflag("-Wno-old-style-cast")
add_cxxflag("-Wno-variadic-macros")
add_cxxflag("-Wno-vla-extension")

@nurupo
Copy link
Member

nurupo commented Dec 4, 2017

@nurupo what compiler flags are you using? what are the minimum flags to use?

You can see what cmake command Travis executes in the build log. It's

cmake -B_build -H. -DCMAKE_INSTALL_PREFIX:PATH=/home/travis/build/TokTok/c-toxcore/_install -DASAN=ON -DDEBUG=ON -DSTRICT_ABI=ON -DTEST_TIMEOUT_SECONDS=120 -DTRACE=ON -DUSE_IPV6=no -DERROR_ON_WARNING=ON -DBUILD_NTOX=ON -DFORMAT_TEST=ON

You would probably want to disable FORMAT_TEST when testing locally, it's used to check code formatting and requires APIDSL and Astyle to be installed, so it will likely fail for you until you set those up.

You might want to additionally set -DCOMPILE_AS_CXX=ON because that is what fails Windows builds.

also, has anybody ever used toxcore on big-endian? i am not sure that all the already existing code is endianness safe

Someone did a year or two ago and there were indeed a couple of issues, but I believe they got fixed. The ones that I remember were about the save_data bytes being dependent on endianness. IF you have found issues with the endianness, then those are likely new and you should document them by opening issues for them.

When toxcore was initially written there was little regard for portability and there weren't many code reviews done. Code quality wasn't very good (but it wasn't very bad either). Things changed after the TokTok fork, code quality requirements became more strict and code reviews became required, CI is testing for a lot more of things now, and we ourselves have learned a great deal of stuff in the process. Most of the improvements were done in toxcore, not toxav, toxencryptsave or others, so that's why you might see not as good code in some places, especially in non-toxcore subdirs.

@zoff99
Copy link
Author

zoff99 commented Dec 5, 2017

i am pretty sure video will not work correctly on bigendian. does anybody have a bigendian system with toxcore to test video?

@zoff99 zoff99 added P0 Critical priority and removed P2 Medium priority labels Dec 5, 2017
@zoff99 zoff99 added this to the v0.1.11 milestone Dec 6, 2017
@robinlinden
Copy link
Member

@zoff99 Travis still doesn't like it: https://travis-ci.org/TokTok/c-toxcore/jobs/312062622#L2205
You have errors related to casting away const from things, unused variables, and bit shifting setting the sign bit on a signed integer type.

@zoff99
Copy link
Author

zoff99 commented Dec 6, 2017

@robinlinden i will check this.
until then can you test this version if it works fine in your setup? that would be an important information.

@zoff99 zoff99 changed the title WIP: video fix (2nd) video fix (2nd) Dec 10, 2017
@zoff99
Copy link
Author

zoff99 commented Dec 10, 2017

includes:

  • full Video fix (compatible with existing old clients)
  • codec autodetection on the receiver end (can already detect and play VP9)
  • multithreaded encoder
  • multithreaded decoder
  • error resilient flags set in encoder
    (VPX_ERROR_RESILIENT_DEFAULT | VPX_ERROR_RESILIENT_PARTITIONS)
  • allow overlapping video packets to be decoded (late packets)

@sudden6
Copy link

sudden6 commented Dec 10, 2017

Do you consider this ready for review?

@zoff99
Copy link
Author

zoff99 commented Dec 11, 2017

@sudden6 in terms of functionality yes.
i think i need 1 more patch from travis for the formatting.

before reviewing, it would be best if a few people could test this if it works as expected?

@Diadlo
Copy link

Diadlo commented Dec 14, 2017

@zoff99 I found this
Maybe we can run both endian tests with this?

@zoff99
Copy link
Author

zoff99 commented Dec 14, 2017

@Diadlo i am sure bigendian does not work with current release version also. so it will not work with my fix aswell.
maybe we want to open a new issue "full bigendian support"?

@robinlinden robinlinden removed this from the v0.1.11 milestone Dec 17, 2017
@sudden6
Copy link

sudden6 commented Jan 4, 2018

Ok, I went over this huge PR and marked a lot of the stuff I think absolutely needs changes. It took 1,5h...

To accelerate this the next time this PR should be split into at least 3 parts

  • The logger changes
  • The changes having to do with reassembling keyframes
  • introducing support for vp9 (seems to be independent)

Not sure if it makes sense to do that over git or just copy the state of the relevant to new branches each.

Some general stuff:

  • lots of formatting issues, please run at least some tool to limit the line length to 80 chars (I think this is c-toxcore style) and remove the blocks of empty lines
  • lots of #if 0 code from the prototyping phase -> remove

Review status: 0 of 15 files reviewed at latest revision, 57 unresolved discussions, some commit checks broke.


circle.yml, line 124 at r2 (raw file):

test:
  override:
  - make test V=1 ARGS="-V" ; ex1=$? ; if [ $ex1 -ne 0 ]; then sleep 60; make test V=1 ARGS="-V" ; exit $? ; fi

Should this be part of this PR or has this PR a dependency on something else?


toxav/audio.c, line 60 at r2 (raw file):

    int status;
    ac->decoder = opus_decoder_create(AUDIO_DECODER__START_SAMPLING_RATE, AUDIO_DECODER__START_CHANNEL_COUNT, &status);

line length


toxav/audio.c, line 76 at r2 (raw file):

    /* Initialize encoders with default values */
    ac->encoder = create_audio_encoder(log, AUDIO_START_BITRATE_RATE, AUDIO_START_SAMPLING_RATE, AUDIO_START_CHANNEL_COUNT);

line length


toxav/audio.c, line 134 at r2 (raw file):

    }

    /* TODO(mannol): fix this and jitter buffering */

still relevant?


toxav/audio.c, line 136 at r2 (raw file):

    /* TODO(mannol): fix this and jitter buffering */

    /* Enough space for the maximum frame size (120 ms 48 KHz stereo audio) */

comment out of sync with the code?


toxav/audio.h, line 32 at r2 (raw file):

#define AUDIO_JITTERBUFFER_COUNT (3)

A comment explaining what this setting does would be good, does it buffer samples, packets?


toxav/audio.h, line 38 at r2 (raw file):

#define AUDIO_START_SAMPLING_RATE (48000)
#define AUDIO_START_BITRATE_RATE (48000)
#define AUDIO_START_CHANNEL_COUNT (2)

Are START the encoder settings? If so, shouldn't the encoder and decoder start with the same values anyway?

If separate settings are really needed, please make the naming convention more uniform, I suggest AUDIO_ENC_* and AUDIO_DEC_* for encoder/decoder settings.


toxav/bwcontroller.c, line 35 at r2 (raw file):

#define BWC_PACKET_ID 196
#define BWC_SEND_INTERVAL_MS (950)     /* 0.95s  */

Is there any reasoning behind the chosen values and can you put that in the comments?


toxav/bwcontroller.c, line 42 at r2 (raw file):

/**
 *
 */

Remove empty comment


toxav/bwcontroller.c, line 98 at r2 (raw file):

    /* Fill with zeros */
    for (i = 0; i < BWC_AVG_PKT_COUNT; i++) {

C99 allows to do for(int i= 0; ... and it's the preferred way to do such copy loops


toxav/bwcontroller.c, line 123 at r2 (raw file):

void bwc_feed_avg(BWController *bwc, uint32_t bytes)
{
    // DISABLE

delete instead of disabling


toxav/bwcontroller.c, line 145 at r2 (raw file):

    // DISABLE
    return;

delete instead of disabling


toxav/bwcontroller.c, line 197 at r2 (raw file):

    }

    // LOGGER_WARNING(bwc->m->log, "BWC recv: %d", (int)recv_bytes);

remove debugging comment


toxav/bwcontroller.c, line 208 at r2 (raw file):

{

#if 0

delete instead of disabling


toxav/bwcontroller.c, line 220 at r2 (raw file):

#endif

    //if (current_time_monotonic() - bwc->cycle.last_sent_timestamp > BWC_SEND_INTERVAL_MS) {

remove testing code


toxav/bwcontroller.c, line 228 at r2 (raw file):

                LOGGER_INFO(bwc->m->log, "%p Sent update rcv: %u lost: %u percent: %f %%",
                            bwc, bwc->cycle.recv, bwc->cycle.lost,
                            (float)(((float) bwc->cycle.lost / (bwc->cycle.recv + bwc->cycle.lost)) * 100.0f));

outer float cast is unneeded because the calculation is already in float


toxav/bwcontroller.c, line 265 at r2 (raw file):

    uint32_t lost = net_ntohl(msg->lost);

    // LOGGER_INFO(bwc->m->log, "recved: %u lost: %u", recv, lost);

why removed?


toxav/bwcontroller.c, line 270 at r2 (raw file):

        LOGGER_INFO(bwc->m->log, "recved: %u lost: %u percentage: %f %%", recv, lost,
                    (float)(((float) lost / (recv + lost)) * 100.0f));

outer float cast unneeded


toxav/ring_buffer.c, line 28 at r2 (raw file):

struct RingBuffer {
    uint16_t size; /* Max size */
// Zoff --

Why does a generic ring buffer need a byte for the data type?


toxav/ring_buffer.c, line 48 at r2 (raw file):

/*
 * returns: NULL on success
            start address of ?? on FAILURE

fill out ??


toxav/rtp.c, line 103 at r2 (raw file):

                     (int)session_v3->work_buffer_list->next_free_entry);

        if (session_v3->work_buffer_list->next_free_entry > 0) {

If without effect


toxav/rtp.c, line 165 at r2 (raw file):

        // TOX RTP V3 --- hack to get frame type ---
        //
        // use the highest bit (bit 31) to spec. keyframe = 1 / no keyframe = 0

does that mean keyframes allways have the highest bit set and others are guaranteed to not have it set?


toxav/rtp.c, line 169 at r2 (raw file):

        // and assume its a keyframe (most likely is anyway)

        if (LOWER_31_BITS(length_v3) > 0x1FFFFFFF) {

Are you sure you don't want to compare against UINT16_MAX , or where does that magic 0x1FFFFFFF come from?


toxav/rtp.c, line 172 at r2 (raw file):

            is_keyframe = 1;
        } else {
            is_keyframe = (length_v3 & (uint32_t)(1L << 31)) != 0; // 1-> is keyframe, 0-> no keyframe

It's needed to do the cast like this (length_v3 & ((uint32_t)1 << 31)) != 0 or you risk shifting into the sign bit, which is undefined.


toxav/rtp.c, line 217 at r2 (raw file):

    header_v3->data_length_full = net_htonl(length_v3); // without header

    header_v3->offset_lower = net_htons((uint16_t)(0));

why do you cast 0?


toxav/rtp.c, line 261 at r2 (raw file):

            header->cpart = net_htons((uint16_t)sent);

// Zoff -- new stuff --

remove unneccessary comments


toxav/rtp.c, line 339 at r2 (raw file):

        uint32_t offset, uint32_t full_data_length, uint8_t is_keyframe)
{
    // assert(allocate_len >= data_length);

why uncommented?


toxav/rtp.c, line 343 at r2 (raw file):

    struct RTPMessage *msg = (
                                 struct RTPMessage *)calloc(1,
                                         sizeof(struct RTPMessage) + (allocate_len)

formatting


toxav/rtp.c, line 368 at r2 (raw file):

static void move_slot(struct RTPWorkBufferList *wkbl, int8_t dst_slot, int8_t src_slot)

Could use some documentation


toxav/rtp.c, line 376 at r2 (raw file):

static int8_t get_slot(Logger *log, struct RTPWorkBufferList *wkbl, uint8_t is_keyframe,

This function could use some documentation what it's doing, because it's really complex


toxav/rtp.c, line 385 at r2 (raw file):

        int i;

        for (i = 0; i < wkbl->next_free_entry; i++) {

use C99 for


toxav/rtp.c, line 393 at r2 (raw file):

        }

        if (wkbl->next_free_entry < USED_RTP_WORKBUFFER_COUNT) {

It seems to me, from here on, this if part is identical to the else part and could be simplified by ending the if (is_multipart == 1) here and deleting the else part.


toxav/rtp.c, line 410 at r2 (raw file):

                return -2;
            } else {
                // LOGGER_WARNING(log, "workbuffer:2b:timestamp prev=%d cur=%d", (int)wkbl->work_buffer[wkbl->next_free_entry - 1].timestamp , (int)net_ntohl(header_v3->timestamp));

debug message needed?


toxav/rtp.c, line 509 at r2 (raw file):

    if (slot > -1) {

change to slot < 0 and use early return


toxav/rtp.c, line 594 at r2 (raw file):

    /*
     *

This comment makes no sense to me


toxav/rtp.c, line 620 at r2 (raw file):

    if (offset_v3 >= length_v3) {
        /* Never allow this case to happen */
        LOGGER_ERROR(m->log, "Never allow this case to happen");

A reason "why" this should never happen would be very helpful


toxav/rtp.c, line 661 at r2 (raw file):

            if (slot == -2) {
                if (m_new) {
                    free(m_new);

remove if it's allowed to free(NULL)


toxav/rtp.c, line 683 at r2 (raw file):

                struct RTPMessage *m_new = process_frame(m->log, work_buffer_list, slot);

                if (m_new) {

you can merge if (m_new) && (session->mcb)


toxav/rtp.c, line 698 at r2 (raw file):

#if 0

remove ifdefed out code if not needed


toxav/rtp.c, line 746 at r2 (raw file):

            if (slot == -2) {
                if (m_new) {
                    free(m_new);

remove if it's allowed to free(NULL)


toxav/rtp.c, line 825 at r2 (raw file):

    // everything below here is protocol version 2 ------------------

one time is probably enough


toxav/rtp.h, line 35 at r2 (raw file):

enum {
    rtp_TypeAudio = 192,
    rtp_TypeVideo, // = 193

a comment with the literal value of an enum is pretty useless, either the value is explicit by the protocl, then use rtp_TypeVideo = 193 or the literal value doesn't matter anyway and should never be directly used.


toxav/rtp.h, line 41 at r2 (raw file):

enum {
    video_frame_type_NORMALFRAME = 0,
    video_frame_type_KEYFRAME, // = 1

same


toxav/rtp.h, line 82 at r2 (raw file):

// #define LOWER_31_BITS(x) (x & ((int)(1L << 31) - 1))
#define LOWER_31_BITS(x) (uint32_t)(x & 0x7fffffff)

I think we should use #define LOWER_31_BITS(x) (uint32_t)(x & (((uint32_t)1 << 31) - 1)) here, since it both makes it clear that there are 31 bits set and doesn't shift into the sign bit.


toxav/toxav.c, line 41 at r2 (raw file):

// TODO: don't hardcode this, let the application choose it
// VPX Info: Time to spend encoding, in microseconds (it's a *soft* deadline)
#define WANTED_MAX_ENCODER_FPS (40)

IMO this should be higher by default because a normal desktop can handle probably more than that.
why is this block here and in video.c?


toxav/toxav.c, line 799 at r2 (raw file):

    int vpx_encode_flags = 0;

#if 1

remove useles #if


toxav/toxav.c, line 876 at r2 (raw file):

                uint32_t frame_length_in_bytes = pkt->data.frame.sz;

                if (LOWER_31_BITS(frame_length_in_bytes) > 0x1FFFFFFF) {

use <= to remove empty if path


toxav/toxav.c, line 879 at r2 (raw file):

                } else {
                    if (keyframe == 1) {
                        frame_length_in_bytes = (uint32_t)(1L << 31) | LOWER_31_BITS(frame_length_in_bytes);

use ((uint32_t)1 << 31)


toxav/toxav.c, line 904 at r2 (raw file):

                    rc = TOXAV_ERR_SEND_FRAME_RTP_FAILED;
                    goto END;
                } else {

remove empty else


toxav/video.c, line 138 at r2 (raw file):

    cfg->g_threads = VPX_MAX_ENCODER_THREADS; // Maximum number of threads to use

    // cfg->g_timebase.num = 1;

still needed?


toxav/video.c, line 147 at r2 (raw file):

    cfg->rc_resize_down_thresh = 5;

#if 0

why disabled?


toxav/video.c, line 245 at r2 (raw file):

Waaay to much whitespace here


toxav/video.c, line 274 at r2 (raw file):

same


toxav/video.c, line 729 at r2 (raw file):

        if (VPX_ENCODER_USED == VPX_VP9_CODEC) {
            if (1 == 2) {

????


toxcore/LAN_discovery.c, line 359 at r2 (raw file):

    char ip_str[IP_NTOA_LEN] = { 0 };
    ip_ntoa(&source.ip, ip_str, sizeof(ip_str));
    LOGGER_DEBUG(dht->log, "Found node in LAN: %s", ip_str);

should probably not be part of this PR


toxcore/logger.c, line 70 at r2 (raw file):

    /* Format message */
    char msg[LOGGER_MAX_MSG_LENGTH];

same


toxcore/logger.h, line 34 at r2 (raw file):

#ifndef LOGGER_MAX_MSG_LENGTH
#define LOGGER_MAX_MSG_LENGTH (2048) // ORIG 1024

same


Comments from Reviewable

@sudden6
Copy link

sudden6 commented Jan 4, 2018

I did not test this PR yet

@iphydf
Copy link
Member

iphydf commented Jan 21, 2018

Review status: 5 of 12 files reviewed at latest revision, 48 unresolved discussions, some commit checks failed.


toxav/bwcontroller.c, line 92 at r6 (raw file):

Previously, zoff99 (Zoff) wrote…

its not needed but good practice to see what values should be initialised to.
otherwise it could be zero just by accident

*sigh* reluctantly OK.


toxav/video.c, line 41 at r6 (raw file):

Previously, zoff99 (Zoff) wrote…

no its max fps. less fps is possible, but not more.
if the CPU is the bottleneck that is

OK


toxav/video.c, line 459 at r6 (raw file):

Previously, zoff99 (Zoff) wrote…

please lets leave it like this. RTPMessage is already "frankenstein"

ok


Comments from Reviewable

@iphydf
Copy link
Member

iphydf commented Jan 21, 2018

Reviewed 5 of 7 files at r8, 2 of 2 files at r9.
Review status: all files reviewed at latest revision, 47 unresolved discussions, some commit checks failed.


Comments from Reviewable

@sudden6
Copy link

sudden6 commented Jan 21, 2018

toxav/rtp.c, line 343 at r2 (raw file):

Previously, zoff99 (Zoff) wrote…

hm, why does astyle not fix this?

I don't know


Comments from Reviewable

@iphydf iphydf force-pushed the zoff99/_0.1.10_2017_video_fix_03x branch from f606e7f to c91a421 Compare January 21, 2018 14:36
@iphydf iphydf force-pushed the zoff99/_0.1.10_2017_video_fix_03x branch from c91a421 to a6a1770 Compare January 21, 2018 14:41
@iphydf iphydf changed the title video fix (2nd) Fix high quality video sending. Jan 21, 2018
@sudden6
Copy link

sudden6 commented Jan 21, 2018

Review status: all files reviewed at latest revision, 35 unresolved discussions.


circle.yml, line 124 at r2 (raw file):

Previously, zoff99 (Zoff) wrote…

Done.

probably easier to merge this in a separate PR then.


toxav/bwcontroller.c, line 35 at r2 (raw file):

Previously, zoff99 (Zoff) wrote…

i am going to leave them as is for now. i tested with those.

then please add a comment like experimentally choosen so everybody knows this value can be changed to improve things


toxav/bwcontroller.c, line 92 at r6 (raw file):

Previously, zoff99 (Zoff) wrote…

its not needed but good practice to see what values should be initialised to.
otherwise it could be zero just by accident

@zoff99 calloc guarantees the memory is zero initialized.


toxav/ring_buffer.c, line 28 at r2 (raw file):

Previously, zoff99 (Zoff) wrote…

if there are more then 1 extra thing needed sure. but 1 value is ok i think

The usual way to solve this problem is, to put the ring buffer in a struct with a description field. This way the ring buffer api can stay generic and you still have only one extra byte.


toxav/ring_buffer.c, line 98 at r8 (raw file):

        free(buf->data);
        free(buf);
        return NULL;        

extra spaces


toxav/rtp.c, line 165 at r2 (raw file):

Previously, zoff99 (Zoff) wrote…

yes

I think the logic in the whole block can be simplified like this:

if(length_v3 & ((uint32_t) 1 << 31))

which is the standard way to check for set bits in C


toxav/rtp.c, line 169 at r2 (raw file):

Previously, zoff99 (Zoff) wrote…

if the size of the frame is larger than 0x1FFFFFFF then index frame flag is implied.

Where do you get the value 0x1FFFFFFF from?


toxav/rtp.c, line 594 at r2 (raw file):

Previously, zoff99 (Zoff) wrote…

is there a better way to write it?

maybe explain why these functions are listed here?


toxav/rtp.c, line 620 at r2 (raw file):

Previously, zoff99 (Zoff) wrote…

its just copied from existing check in line 804

If you can't figure out why, add a todo or fixme comment.


toxav/rtp.c, line 362 at r8 (raw file):

static struct RTPMessage *process_oldest_frame(Logger *log, struct RTPWorkBufferList *wkbl)
{
    if (wkbl->next_free_entry > 0) {

is wkbl guaranteed to be not NULL?


toxav/rtp.h, line 82 at r2 (raw file):

Previously, zoff99 (Zoff) wrote…

Done.

What's the TODO: about? Remove the commented out piece of code


toxav/toxav.c, line 876 at r2 (raw file):

Previously, zoff99 (Zoff) wrote…

i dont understand this one

inverted the condition to LOWER_31_BITS(frame_length_in_bytes) <= 0x1FFFFFFF, exchange the if and else code paths and remove the now empty else code path


toxav/toxav.c, line 887 at r10 (raw file):

                if (res < 0) {
                    pthread_mutex_unlock(call->mutex_video);

Is it important/correct to unlock the mutex before the logger call and setting rc?


toxav/video.c, line 138 at r2 (raw file):

Previously, zoff99 (Zoff) wrote…

hm actually leave it here as hint. it should be set to a correcgt value (next PR)

Ok


toxav/video.c, line 147 at r2 (raw file):

Previously, zoff99 (Zoff) wrote…

Done.

Ok


toxav/audio.h, line 32 at r2 (raw file):

Previously, zoff99 (Zoff) wrote…

Done.

I still see no comment?


Comments from Reviewable

@iphydf iphydf force-pushed the zoff99/_0.1.10_2017_video_fix_03x branch from 7263d33 to b438010 Compare January 21, 2018 16:01
@jhert0
Copy link
Member

jhert0 commented Jan 21, 2018

Reviewed 1 of 2 files at r5, 2 of 9 files at r6, 2 of 7 files at r7, 4 of 7 files at r8, 1 of 2 files at r9, 3 of 3 files at r11, 1 of 3 files at r12.
Review status: 11 of 13 files reviewed at latest revision, 43 unresolved discussions, some commit checks failed.


testing/av_test.c, line 210 at r12 (raw file):

    pthread_mutex_lock(cc->arb_mutex);
    free(rb_write(cc->arb, f, 0));

rb_write can retrun NULL


toxav/rtp.c, line 169 at r2 (raw file):

Previously, sudden6 wrote…

Where do you get the value 0x1FFFFFFF from?

Create a constant for 0x1FFFFFFF


toxav/rtp.c, line 281 at r11 (raw file):

        uint32_t offset, uint32_t full_data_length, uint8_t is_keyframe)
{
    struct RTPMessage *msg = (struct RTPMessage *)calloc(1, sizeof(struct RTPMessage) + allocate_len);

Make sure memory is allocated for msg.


toxav/rtp.c, line 303 at r11 (raw file):

static void move_slot(struct RTPWorkBufferList *wkbl, int8_t dst_slot, int8_t src_slot)
{
    memcpy(&(wkbl->work_buffer[dst_slot]), &(wkbl->work_buffer[src_slot]), sizeof(struct RTPWorkBuffer));

Add a check to make sure dst_slot isn't larger than USED_RTP_WORKBUFFER_COUNT;


toxav/rtp.c, line 496 at r11 (raw file):

    if (session_v3->work_buffer_list == NULL) {
        session_v3->work_buffer_list = (struct RTPWorkBufferList *)calloc(1, sizeof(struct RTPWorkBufferList));

Make sure memory is allocated.


toxav/rtp.c, line 560 at r11 (raw file):

            if (slot == -2) {
                free(m_new);

Possible double free, m_new is freed above when session->mcb == NULL


toxav/rtp.c, line 621 at r11 (raw file):

            if (slot == -2) {
                free(m_new);

Possible double free, m_new is freed above when session->mcb == NULL


toxav/video.c, line 536 at r11 (raw file):

            (uint8_t)header_v3->pt == (rtp_TypeVideo % 128)) {
        LOGGER_DEBUG(vc->log, "rb_write msg->len=%d b0=%d b1=%d", (int)msg->len, (int)msg->data[0], (int)msg->data[1]);
        free(rb_write((RingBuffer *)vc->vbuf_raw, msg, (uint8_t)header_v3->is_keyframe));

rb_write can return NULL.


toxav/video.c, line 538 at r11 (raw file):

        free(rb_write((RingBuffer *)vc->vbuf_raw, msg, (uint8_t)header_v3->is_keyframe));
    } else {
        free(rb_write((RingBuffer *)vc->vbuf_raw, msg, 0));

rb_write can return NULL.


Comments from Reviewable

@jhert0
Copy link
Member

jhert0 commented Jan 21, 2018

Reviewed 2 of 3 files at r12.
Review status: all files reviewed at latest revision, 43 unresolved discussions, some commit checks failed.


Comments from Reviewable

@iphydf iphydf force-pushed the zoff99/_0.1.10_2017_video_fix_03x branch from b438010 to d9a0148 Compare January 21, 2018 17:06
iphydf added a commit to iphydf/c-toxcore that referenced this pull request Jan 21, 2018
@iphydf iphydf force-pushed the zoff99/_0.1.10_2017_video_fix_03x branch from 6b63bff to 53250c0 Compare January 21, 2018 17:39
iphydf added a commit to iphydf/c-toxcore that referenced this pull request Jan 21, 2018
@zugz
Copy link

zugz commented Jan 21, 2018

Review status: 7 of 10 files reviewed at latest revision, 51 unresolved discussions.


toxav/bwcontroller.c, line 36 at r11 (raw file):

#define BWC_PACKET_ID 196
#define BWC_SEND_INTERVAL_MS 950     /* 0.95s  */
#define BWC_REFRESH_INTERVAL_MS 2000 /* 2.00s */

BWC_REFRESH_INTERVAL_MS is no longer used; delete?


toxav/bwcontroller.c, line 37 at r12 (raw file):

#define BWC_SEND_INTERVAL_MS 950     /* 0.95s  */
#define BWC_REFRESH_INTERVAL_MS 2000 /* 2.00s */
#define BWC_AVG_PKT_COUNT 20

BWC_AVG_PKT_COUNT is no longer used, nor is rcvpkt. Delete them?


toxav/bwcontroller.c, line 166 at r12 (raw file):

    LOGGER_DEBUG(bwc->m->log, "%p Got update from peer", bwc);

    /* Peers sent update too soon */

Should be "Peer"?


toxav/rtp.c, line 64 at r13 (raw file):

    retu->friend_number = friendnumber;
    // set NULL just in case
    retu->mp = NULL;

Already NULL, from calloc


toxav/rtp.c, line 148 at r13 (raw file):

    if (is_video_payload == 1) {
        // TOX RTP V3 --- hack to get frame type ---

This is a pretty nasty hack! Generally, keeping track of whether a frame is a keyframe seems to be leading to a lot of unpleasantness. Is it really necessary? Could it make sense to just treat unusually large frames specially, rather than keyframes in particular?


toxav/rtp.c, line 210 at r13 (raw file):

        while (lost --) {
            bwc_add_lost(session->bwc, 0);
        }

Will deleting this break bwc for v2 packets?


toxav/rtp.h, line 88 at r12 (raw file):

#ifndef WORDS_BIGENDIAN
    uint16_t cc: 4; /* Contributing sources count */
    uint16_t is_keyframe: 1;

This makes no sense in terms of the RTP standard. We could stay within the RTP spec by putting the extra information after the csrcs in a "header extension". I don't know if there's actually any value to sticking to the RTP spec, but it seems perverse to do so partially but not fully.


toxav/rtp.h, line 109 at r12 (raw file):

    uint32_t offset_full; /* Data offset of the current part */
    uint32_t data_length_full; /* data length without header, and without packet id */
    uint32_t received_length_full; /* only the receiver uses this field */

Again, these 3 should be in csrc according to the RTP spec.


Comments from Reviewable

@iphydf
Copy link
Member

iphydf commented Jan 25, 2018

Closing this in favour of the WIP patch series I'm building. We'll work on those branches together and I'll manage the git rebases.

@iphydf iphydf closed this Jan 25, 2018
@iphydf iphydf added refactor Refactoring production code, eg. renaming a variable, not affecting semantics and removed code cleanup labels May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P0 Critical priority refactor Refactoring production code, eg. renaming a variable, not affecting semantics toxav Audio/video
Projects
None yet
Development

Successfully merging this pull request may close these issues.