资源简介
ffmpeg+websocket+jsmpeg实现html播放rtsp实时视频流,它主要是通过webSocket发送MPEG,前端通过js解析MPEG不断绘制canvas,包括音频。最终测试的结果就是一个1920*1080分辨率的画面延时大概的0.5s左右
代码片段和文件信息
#include
#include
#include
#include “buffer.h“
typedef struct bit_buffer_t {
uint8_t *bytes;
unsigned int index;
unsigned int byte_capacity;
unsigned int byte_length;
bit_buffer_mode_t mode;
} bit_buffer_t;
void bit_buffer_resize(bit_buffer_t *self unsigned int byte_capacity);
void bit_buffer_evict(bit_buffer_t *self unsigned int bytes_needed);
bit_buffer_t *bit_buffer_create(unsigned int initial_byte_capacity bit_buffer_mode_t mode) {
bit_buffer_t *self = malloc(sizeof(bit_buffer_t));
self->mode = mode;
self->bytes = malloc(initial_byte_capacity);
self->byte_capacity = initial_byte_capacity;
self->byte_length = 0;
self->index = 0;
return self;
}
void bit_buffer_destroy(bit_buffer_t *self) {
free(self->bytes);
free(self);
}
int bit_buffer_get_index(bit_buffer_t *self) {
return self->index;
}
void bit_buffer_set_index(bit_buffer_t *self unsigned int index) {
self->index = index; // TODO check validity!
}
uint8_t *bit_buffer_get_write_ptr(bit_buffer_t *self unsigned int bytes_to_write) {
int bytes_available = self->byte_capacity - self->byte_length;
if (bytes_to_write > bytes_available) {
if (self->mode == BIT_BUFFER_MODE_EXPAND) {
int new_byte_capacity = self->byte_capacity * 2;
if (new_byte_capacity + bytes_available < bytes_to_write) {
new_byte_capacity = bytes_to_write - bytes_available;
}
bit_buffer_resize(self new_byte_capacity);
}
else {
bit_buffer_evict(self bytes_to_write);
}
}
return self->bytes + self->byte_length;
};
void bit_buffer_did_write(bit_buffer_t *self unsigned int bytes_written) {
self->byte_length += bytes_written;
}
int bit_buffer_find_next_start_code(bit_buffer_t *self) {
for (int i = ((self->index + 7) >> 3); i < self->byte_length; i++) {
if(
self->bytes[i] == 0x00 &&
self->bytes[i+1] == 0x00 &&
self->bytes[i+2] == 0x01
) {
self->index = (i+4) << 3;
return self->bytes[i+3];
}
}
self->index = (self->byte_length << 3);
return -1;
}
int bit_buffer_find_start_code(bit_buffer_t *self int code) {
int current = 0;
while (true) {
current = bit_buffer_find_next_start_code(self);
if (current == code || current == -1) {
return current;
}
}
return -1;
}
int bit_buffer_next_bytes_are_start_code(bit_buffer_t *self) {
int i = ((self->index + 7) >> 3);
return (
i >= self->byte_length || (
self->bytes[i] == 0x00 &&
self->bytes[i+1] == 0x00 &&
self->bytes[i+2] == 0x01
)
);
}
int bit_buffer_peek(bit_buffer_t *self unsigned int count) {
int offset = self->index;
int value = 0;
while (count) {
int current_byte = self->bytes[offset >> 3];
int remaining = 8 - (offset & 7); // remaining bits in byte
int read = remaining < count ? remaining : count; // bits in self run
int shift = remaining - read;
int mask = (0xff >> (8-read));
value = (value << read) | ((current_byte & (mask << shift)) >> shift);
offset += read;
count -= read;
}
return value;
}
int b
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2020-03-02 17:22 jsmpeg-master\
文件 2273 2019-05-28 22:22 jsmpeg-master\build.sh
文件 139179 2019-05-28 22:22 jsmpeg-master\jsmpeg.min.js
文件 1084 2019-05-28 22:22 jsmpeg-master\LICENSE
目录 0 2020-03-02 17:25 jsmpeg-master\node_modules\
目录 0 2020-03-02 17:25 jsmpeg-master\node_modules\ws\
文件 175 1985-10-26 16:15 jsmpeg-master\node_modules\ws\browser.js
文件 296 1985-10-26 16:15 jsmpeg-master\node_modules\ws\index.js
目录 0 2020-03-02 17:25 jsmpeg-master\node_modules\ws\lib\
文件 3389 1985-10-26 16:15 jsmpeg-master\node_modules\ws\lib\buffer-util.js
文件 268 1985-10-26 16:15 jsmpeg-master\node_modules\ws\lib\constants.js
文件 3937 1985-10-26 16:15 jsmpeg-master\node_modules\ws\lib\event-target.js
文件 6883 1985-10-26 16:15 jsmpeg-master\node_modules\ws\lib\extension.js
文件 981 1985-10-26 16:15 jsmpeg-master\node_modules\ws\lib\limiter.js
文件 14239 1985-10-26 16:15 jsmpeg-master\node_modules\ws\lib\permessage-deflate.js
文件 11968 1985-10-26 16:15 jsmpeg-master\node_modules\ws\lib\receiver.js
文件 9523 1985-10-26 16:15 jsmpeg-master\node_modules\ws\lib\sender.js
文件 3410 1985-10-26 16:15 jsmpeg-master\node_modules\ws\lib\stream.js
文件 695 1985-10-26 16:15 jsmpeg-master\node_modules\ws\lib\validation.js
文件 11460 1985-10-26 16:15 jsmpeg-master\node_modules\ws\lib\websocket-server.js
文件 24275 1985-10-26 16:15 jsmpeg-master\node_modules\ws\lib\websocket.js
文件 1106 1985-10-26 16:15 jsmpeg-master\node_modules\ws\LICENSE
文件 2542 2020-03-02 17:25 jsmpeg-master\node_modules\ws\package.json
文件 13769 1985-10-26 16:15 jsmpeg-master\node_modules\ws\README.md
文件 299 2020-03-02 17:22 jsmpeg-master\package-lock.json
文件 14827 2019-05-28 22:22 jsmpeg-master\README.md
目录 0 2020-03-02 17:20 jsmpeg-master\src\
文件 3326 2019-05-28 22:22 jsmpeg-master\src\ajax-progressive.js
文件 1517 2019-05-28 22:22 jsmpeg-master\src\ajax.js
文件 4498 2019-05-28 22:22 jsmpeg-master\src\buffer.js
文件 2873 2019-05-28 22:22 jsmpeg-master\src\canvas2d.js
............此处省略23个文件信息
- 上一篇:Aspose.Word使用说明文档.pdf
- 下一篇:一个页面的设计
评论
共有 条评论