MCPcopy Create free account
hub / github.com/alibaba/CicadaPlayer / testSliceBuffer

Function testSliceBuffer

framework/data_source/cache/sliceTest.cpp:51–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51void testSliceBuffer()
52{
53 IDataSource *source = DataSourceFactory::create("http://player.alicdn.com/video/aliyunmedia.mp4");
54 int ret = source->Open(0);
55
56 if (ret < 0) {
57 AF_LOGE("source open error\n");
58 return;
59 }
60
61 auto fileSize = static_cast<uint64_t>(source->Seek(0, SEEK_SIZE));
62 sliceBuffer *buffer = new sliceBuffer(SLICE_SIZE, fileSize, nullptr);
63 AF_LOGD("fileSize is %d\n", fileSize);
64 uint8_t *ReadBuffer = new uint8_t[SLICE_SIZE];
65 int writeSize = 0;
66
67 while (true) {
68 ret = readSlice(source, ReadBuffer);
69
70 // AF_LOGD("read %d from source\n",ret);
71 if (ret <= 0) {
72 break;
73 }
74
75 buffer->writeAt(ReadBuffer, ret, writeSize);
76 writeSize += ret;
77 }
78
79 AF_LOGD("writeSize is %d\n", writeSize);
80 source->Close();
81 delete source;
82 int fd = ::open("slice.mp4", O_CREAT | O_WRONLY, 0666);
83 int readSize = 0;
84
85 do {
86 ret = buffer->readAt(ReadBuffer, SLICE_SIZE, readSize);
87
88 if (ret > 0) {
89 ::write(fd, ReadBuffer, ret);
90 readSize += ret;
91 }
92
93 AF_LOGD("ret is %d\n", ret);
94 } while (ret > 0);
95
96 AF_LOGD("readSize is %d\n", readSize);
97 ::close(fd);
98 delete[] ReadBuffer;
99 buffer->dump();
100 delete buffer;
101}
102
103int main()
104{

Callers 1

mainFunction · 0.85

Calls 7

readSliceFunction · 0.85
writeAtMethod · 0.80
OpenMethod · 0.45
SeekMethod · 0.45
CloseMethod · 0.45
readAtMethod · 0.45
dumpMethod · 0.45

Tested by

no test coverage detected