This commit is contained in:
simon987 2020-03-28 13:32:37 -04:00
parent 3c7887db51
commit e6323e28d0
8 changed files with 38 additions and 85 deletions

View File

@ -36,7 +36,7 @@ ExternalProject_Add(
add_library(
scan
libscan/util.c libscan/util.h
libscan/scan.c libscan/scan.h
libscan/scan.h
libscan/macros.h
libscan/text/text.c libscan/text/text.h
@ -101,16 +101,3 @@ target_include_directories(
${LIBXML2_INCLUDE_DIR}
${FFMPEG_INCLUDE_DIR}
)
# test executable
add_executable(
scan_test
test/main.c
)
target_link_libraries(
scan_test
scan
)

View File

@ -1,3 +1,4 @@
*(wip)*
```bash
vcpkg install libarchive pthread tesseract libxml2 ffmpeg

View File

@ -240,10 +240,14 @@ void parse_media_format_ctx(scan_media_ctx_t *ctx, AVFormatContext *pFormatCtx,
if (stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
if (audio_stream == -1) {
meta_line_t *meta_audio = malloc(sizeof(meta_line_t));
meta_audio->key = MetaMediaAudioCodec;
meta_audio->int_val = stream->codecpar->codec_id;
APPEND_META(doc, meta_audio)
const AVCodecDescriptor *desc = avcodec_descriptor_get(stream->codecpar->codec_id);
if (desc != NULL) {
meta_line_t *meta_audio = malloc(sizeof(meta_line_t));
meta_audio->key = MetaMediaAudioCodec;
strcpy(meta_audio->str_val, desc->name);
APPEND_META(doc, meta_audio)
}
append_audio_meta(pFormatCtx, doc);
audio_stream = i;
@ -251,10 +255,18 @@ void parse_media_format_ctx(scan_media_ctx_t *ctx, AVFormatContext *pFormatCtx,
} else if (stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
if (video_stream == -1) {
meta_line_t *meta_vid = malloc(sizeof(meta_line_t));
meta_vid->key = MetaMediaVideoCodec;
meta_vid->int_val = stream->codecpar->codec_id;
APPEND_META(doc, meta_vid)
const AVCodecDescriptor *desc = avcodec_descriptor_get(stream->codecpar->codec_id);
if (desc != NULL) {
meta_line_t *meta_vid = malloc(sizeof(meta_line_t));
meta_vid->key = MetaMediaVideoCodec;
strcpy(meta_vid->str_val, desc->name);
APPEND_META(doc, meta_vid)
}
meta_line_t *meta_audio = malloc(sizeof(meta_line_t));
meta_audio->key = MetaMediaAudioCodec;
APPEND_META(doc, meta_audio)
meta_line_t *meta_w = malloc(sizeof(meta_line_t));
meta_w->key = MetaWidth;

View File

@ -1,24 +0,0 @@
#include "scan.h"
#include <fcntl.h>
#include <unistd.h>
int fs_read(struct vfile *f, void *buf, size_t size) {
if (f->fd == -1) {
f->fd = open(f->filepath, O_RDONLY);
if (f->fd == -1) {
//TODO: log
// LOG_ERRORF(f->filepath, "open(): [%d] %s", errno, strerror(errno))
return -1;
}
}
return read(f->fd, buf, size);
}
void fs_close(struct vfile *f) {
if (f->fd != -1) {
close(f->fd);
}
}

View File

@ -7,6 +7,11 @@
#include "macros.h"
// TODO: global init:
/*
* av_log_set_level(AV_LOG_QUIET);
*/
#define META_INT_MASK 0x80
#define META_STR_MASK 0x40
@ -33,8 +38,8 @@ enum metakey {
MetaWidth = META_INT(2),
MetaHeight = META_INT(3),
MetaMediaDuration = META_LONG(4),
MetaMediaAudioCodec = META_INT(5),
MetaMediaVideoCodec = META_INT(6),
MetaMediaAudioCodec = META_STR(5),
MetaMediaVideoCodec = META_STR(6),
MetaMediaBitrate = META_LONG(7),
MetaArtist = META_STR(8),
MetaAlbum = META_STR(9),
@ -118,12 +123,12 @@ typedef struct parse_job_t {
doc->meta_tail->next = meta;\
doc->meta_tail = meta;\
}
#endif
void fs_close(struct vfile *f);
#define CLOSE_FILE(f) if (f.close != NULL) {f.close(&f);};
int fs_read(struct vfile *f, void *buf, size_t size);
#include "arc/arc.h"
#include "cbr/cbr.h"
#include "ebook/ebook.h"
#include "font/font.h"
#include "media/media.h"
#include "ooxml/ooxml.h"
#include "text/text.h"

View File

@ -1,5 +1,5 @@
#ifndef SIST2_UTIL_H
#define SIST2_UTIL_H
#ifndef SCAN_UTIL_H
#define SCAN_UTIL_H
#include "stdio.h"
#include "stdlib.h"

0
test/.gitkeep Normal file
View File

View File

@ -1,28 +0,0 @@
#include "../libscan/text/text.h"
#include <fcntl.h>
#include "../libscan/arc/arc.h"
#include "../libscan/ebook/ebook.h"
#include "../libscan/ooxml/ooxml.h"
#include "../libscan/font/font.h"
#include <ft2build.h>
#include <freetype/freetype.h>
int main() {
scan_ebook_ctx_t ctx;
ctx.content_size = 100;
vfile_t file;
file.is_fs_file = TRUE;
file.filepath = "/home/simon/Downloads/libscan/CMakeLists.txt";
file.fd = open("/home/simon/Downloads/libscan/CMakeLists.txt", O_RDONLY);
file.read = fs_read;
document_t doc;
doc.meta_head = NULL;
doc.meta_tail = NULL;
doc.size = 200;
parse_ebook(&ctx, &file,"application/pdf", &doc);
}