You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
179 lines
10 KiB
179 lines
10 KiB
/********************************************************
|
|
Copyright (c) <2019> <copyright ErosZy>
|
|
|
|
"Anti 996" License Version 1.0 (Draft)
|
|
|
|
Permission is hereby granted to any individual or legal entity
|
|
obtaining a copy of this licensed work (including the source code,
|
|
documentation and/or related items, hereinafter collectively referred
|
|
to as the "licensed work"), free of charge, to deal with the licensed
|
|
work for any purpose, including without limitation, the rights to use,
|
|
reproduce, modify, prepare derivative works of, distribute, publish
|
|
and sublicense the licensed work, subject to the following conditions:
|
|
|
|
1. The individual or the legal entity must conspicuously display,
|
|
without modification, this License and the notice on each redistributed
|
|
or derivative copy of the Licensed Work.
|
|
|
|
2. The individual or the legal entity must strictly comply with all
|
|
applicable laws, regulations, rules and standards of the jurisdiction
|
|
relating to labor and employment where the individual is physically
|
|
located or where the individual was born or naturalized; or where the
|
|
legal entity is registered or is operating (whichever is stricter). In
|
|
case that the jurisdiction has no such laws, regulations, rules and
|
|
standards or its laws, regulations, rules and standards are
|
|
unenforceable, the individual or the legal entity are required to
|
|
comply with Core International Labor Standards.
|
|
|
|
3. The individual or the legal entity shall not induce, suggest or force
|
|
its employee(s), whether full-time or part-time, or its independent
|
|
contractor(s), in any methods, to agree in oral or written form, to
|
|
directly or indirectly restrict, weaken or relinquish his or her
|
|
rights or remedies under such laws, regulations, rules and standards
|
|
relating to labor and employment as mentioned above, no matter whether
|
|
such written or oral agreements are enforceable under the laws of the
|
|
said jurisdiction, nor shall such individual or the legal entity
|
|
limit, in any methods, the rights of its employee(s) or independent
|
|
contractor(s) from reporting or complaining to the copyright holder or
|
|
relevant authorities monitoring the compliance of the license about
|
|
its violation(s) of the said license.
|
|
|
|
THE LICENSED WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM,
|
|
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
OTHERWISE, ARISING FROM, OUT OF OR IN ANY WAY CONNECTION WITH THE
|
|
LICENSED WORK OR THE USE OR OTHER DEALINGS IN THE LICENSED WORK.
|
|
*********************************************************/
|
|
|
|
#ifndef CODEC_DECODER_TEST_H
|
|
#define CODEC_DECODER_TEST_H
|
|
|
|
#include <iostream>
|
|
#include <stdint.h>
|
|
#include "vassert.h"
|
|
#include "stream/buffer.h"
|
|
#include "demuxer/decoder.h"
|
|
|
|
using namespace std;
|
|
|
|
class TestDecoderFactor : public DecoderFactor {
|
|
public:
|
|
virtual void recvHeaderValue(HeaderValue &value) {
|
|
VASSERT(!value.empty, "");
|
|
VASSERT(value.version == 1, "");
|
|
VASSERT(value.hasAudio, "");
|
|
VASSERT(value.hasVideo, "");
|
|
VASSERT(value.offset == 9, "");
|
|
}
|
|
|
|
virtual void recvBodyValue(shared_ptr<BodyValue> &values) {
|
|
VASSERT(!values->unvalidate, "");
|
|
}
|
|
};
|
|
|
|
void test_decoder_all() {
|
|
uint8_t ptr[] = {
|
|
0x46, 0x4c, 0x56, 0x01, 0x05, 0x00, 0x00, 0x00, 0x09,
|
|
0x00, 0x00, 0x00, 0x00,
|
|
0x12, 0x00, 0x01, 0x6a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0a, 0x6f, 0x6e,
|
|
0x4d, 0x65, 0x74, 0x61, 0x44, 0x61, 0x74, 0x61, 0x08, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x64,
|
|
0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x40, 0x3c, 0x0b, 0x85, 0x1e, 0xb8, 0x51, 0xec,
|
|
0x00, 0x05, 0x77, 0x69, 0x64, 0x74, 0x68, 0x00, 0x40, 0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x00, 0x40, 0x86, 0x80, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x0d, 0x76, 0x69, 0x64, 0x65, 0x6f, 0x64, 0x61, 0x74, 0x61, 0x72, 0x61, 0x74, 0x65,
|
|
0x00, 0x40, 0x9f, 0x55, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x66, 0x72, 0x61, 0x6d, 0x65,
|
|
0x72, 0x61, 0x74, 0x65, 0x00, 0x40, 0x37, 0xf9, 0xdc, 0xdc, 0xfe, 0x09, 0x5d, 0x00, 0x0c, 0x76,
|
|
0x69, 0x64, 0x65, 0x6f, 0x63, 0x6f, 0x64, 0x65, 0x63, 0x69, 0x64, 0x00, 0x40, 0x1c, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x64, 0x61, 0x74, 0x61, 0x72,
|
|
0x61, 0x74, 0x65, 0x00, 0x40, 0x5e, 0xaa, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x61, 0x75,
|
|
0x64, 0x69, 0x6f, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x61, 0x74, 0x65, 0x00, 0x40, 0xe5,
|
|
0x88, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x73, 0x61, 0x6d,
|
|
0x70, 0x6c, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x00, 0x40, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x06, 0x73, 0x74, 0x65, 0x72, 0x65, 0x6f, 0x01, 0x01, 0x00, 0x0c, 0x61, 0x75, 0x64, 0x69,
|
|
0x6f, 0x63, 0x6f, 0x64, 0x65, 0x63, 0x69, 0x64, 0x00, 0x40, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x0b, 0x6d, 0x61, 0x6a, 0x6f, 0x72, 0x5f, 0x62, 0x72, 0x61, 0x6e, 0x64, 0x02, 0x00,
|
|
0x04, 0x6d, 0x70, 0x34, 0x32, 0x00, 0x0d, 0x6d, 0x69, 0x6e, 0x6f, 0x72, 0x5f, 0x76, 0x65, 0x72,
|
|
0x73, 0x69, 0x6f, 0x6e, 0x02, 0x00, 0x01, 0x30, 0x00, 0x11, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74,
|
|
0x69, 0x62, 0x6c, 0x65, 0x5f, 0x62, 0x72, 0x61, 0x6e, 0x64, 0x73, 0x02, 0x00, 0x08, 0x69, 0x73,
|
|
0x6f, 0x6d, 0x6d, 0x70, 0x34, 0x32, 0x00, 0x07, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x02,
|
|
0x00, 0x0d, 0x4c, 0x61, 0x76, 0x66, 0x35, 0x37, 0x2e, 0x31, 0x39, 0x2e, 0x31, 0x30, 0x30, 0x00,
|
|
0x08, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x00, 0x41, 0x5d, 0x36, 0x79, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x09,
|
|
0x00, 0x00, 0x00, 0x00,
|
|
0x09, 0x00, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00,
|
|
0x01, 0x4d, 0x40, 0x1f, 0xff, 0xe1, 0x00, 0x1b, 0x67, 0x4d, 0x40, 0x1f, 0xe8, 0x80, 0x28, 0x02,
|
|
0xdd, 0x80, 0xb5, 0x01, 0x01, 0x01, 0x40, 0x00, 0x00, 0xfa, 0x40, 0x00, 0x2e, 0xe0, 0x03, 0xc6,
|
|
0x0c, 0x44, 0x80, 0x01, 0x00, 0x04, 0x68, 0xeb, 0xaf, 0x20,
|
|
0x00, 0x00, 0x00, 0x00,
|
|
0x08, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaf, 0x00, 0x12, 0x10,
|
|
0x00, 0x00, 0x00, 0x00
|
|
};
|
|
shared_ptr<Buffer> b = make_shared<Buffer>(ptr, 471);
|
|
shared_ptr<DecoderFactor> factor = make_shared<TestDecoderFactor>();
|
|
Decoder decoder;
|
|
decoder.setFactor(factor);
|
|
decoder.decode(b);
|
|
|
|
VASSERT(true, "Whole Data Decode pass");
|
|
}
|
|
|
|
void test_decoder_chunk() {
|
|
uint8_t ptr[] = {
|
|
0x46, 0x4c, 0x56, 0x01, 0x05, 0x00, 0x00, 0x00, 0x09,
|
|
0x00, 0x00, 0x00, 0x00,
|
|
0x12, 0x00, 0x01, 0x6a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0a, 0x6f, 0x6e,
|
|
0x4d, 0x65, 0x74, 0x61, 0x44, 0x61, 0x74, 0x61, 0x08, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x64,
|
|
0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x40, 0x3c, 0x0b, 0x85, 0x1e, 0xb8, 0x51, 0xec,
|
|
0x00, 0x05, 0x77, 0x69, 0x64, 0x74, 0x68, 0x00, 0x40, 0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x06, 0x68, 0x65, 0x69, 0x67, 0x68, 0x74, 0x00, 0x40, 0x86, 0x80, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x0d, 0x76, 0x69, 0x64, 0x65, 0x6f, 0x64, 0x61, 0x74, 0x61, 0x72, 0x61, 0x74, 0x65,
|
|
0x00, 0x40, 0x9f, 0x55, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x66, 0x72, 0x61, 0x6d, 0x65,
|
|
0x72, 0x61, 0x74, 0x65, 0x00, 0x40, 0x37, 0xf9, 0xdc, 0xdc, 0xfe, 0x09, 0x5d, 0x00, 0x0c, 0x76,
|
|
0x69, 0x64, 0x65, 0x6f, 0x63, 0x6f, 0x64, 0x65, 0x63, 0x69, 0x64, 0x00, 0x40, 0x1c, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x64, 0x61, 0x74, 0x61, 0x72,
|
|
0x61, 0x74, 0x65, 0x00, 0x40, 0x5e, 0xaa, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x61, 0x75,
|
|
0x64, 0x69, 0x6f, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x72, 0x61, 0x74, 0x65, 0x00, 0x40, 0xe5,
|
|
0x88, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x73, 0x61, 0x6d,
|
|
0x70, 0x6c, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x00, 0x40, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x06, 0x73, 0x74, 0x65, 0x72, 0x65, 0x6f, 0x01, 0x01, 0x00, 0x0c, 0x61, 0x75, 0x64, 0x69,
|
|
0x6f, 0x63, 0x6f, 0x64, 0x65, 0x63, 0x69, 0x64, 0x00, 0x40, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
0x00, 0x00, 0x0b, 0x6d, 0x61, 0x6a, 0x6f, 0x72, 0x5f, 0x62, 0x72, 0x61, 0x6e, 0x64, 0x02, 0x00,
|
|
0x04, 0x6d, 0x70, 0x34, 0x32, 0x00, 0x0d, 0x6d, 0x69, 0x6e, 0x6f, 0x72, 0x5f, 0x76, 0x65, 0x72,
|
|
0x73, 0x69, 0x6f, 0x6e, 0x02, 0x00, 0x01, 0x30, 0x00, 0x11, 0x63, 0x6f, 0x6d, 0x70, 0x61, 0x74,
|
|
0x69, 0x62, 0x6c, 0x65, 0x5f, 0x62, 0x72, 0x61, 0x6e, 0x64, 0x73, 0x02, 0x00, 0x08, 0x69, 0x73,
|
|
0x6f, 0x6d, 0x6d, 0x70, 0x34, 0x32, 0x00, 0x07, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x02,
|
|
0x00, 0x0d, 0x4c, 0x61, 0x76, 0x66, 0x35, 0x37, 0x2e, 0x31, 0x39, 0x2e, 0x31, 0x30, 0x30, 0x00,
|
|
0x08, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x69, 0x7a, 0x65, 0x00, 0x41, 0x5d, 0x36, 0x79, 0x00, 0x00,
|
|
0x00, 0x00, 0x00, 0x00, 0x09,
|
|
0x00, 0x00, 0x00, 0x00,
|
|
0x09, 0x00, 0x00, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00,
|
|
0x01, 0x4d, 0x40, 0x1f, 0xff, 0xe1, 0x00, 0x1b, 0x67, 0x4d, 0x40, 0x1f, 0xe8, 0x80, 0x28, 0x02,
|
|
0xdd, 0x80, 0xb5, 0x01, 0x01, 0x01, 0x40, 0x00, 0x00, 0xfa, 0x40, 0x00, 0x2e, 0xe0, 0x03, 0xc6,
|
|
0x0c, 0x44, 0x80, 0x01, 0x00, 0x04, 0x68, 0xeb, 0xaf, 0x20,
|
|
0x00, 0x00, 0x00, 0x00,
|
|
0x08, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaf, 0x00, 0x12, 0x10,
|
|
0x00, 0x00, 0x00, 0x00
|
|
};
|
|
shared_ptr<Buffer> b = make_shared<Buffer>(ptr, 471);
|
|
shared_ptr<DecoderFactor> factor = make_shared<TestDecoderFactor>();
|
|
Decoder decoder;
|
|
decoder.setFactor(factor);
|
|
|
|
while (b->get_length() > 0) {
|
|
shared_ptr<Buffer> b1 = make_shared<Buffer>(b->slice(0, 50));
|
|
decoder.decode(b1);
|
|
b = make_shared<Buffer>(b->slice(b->get_length() > 50 ? 50 : b->get_length()));
|
|
}
|
|
|
|
VASSERT(true, "Chunk Data Decode pass");
|
|
}
|
|
|
|
void test_decoder() {
|
|
cout << "\033[33m " << "decoder: \033[0m" << endl;
|
|
test_decoder_all();
|
|
test_decoder_chunk();
|
|
}
|
|
|
|
#endif //CODEC_DECODER_TEST_H
|
|
|