ref: 5e5feb8fc8da3889301dabe105f7680488c99caf
parent: eaadd4c4e7232a8ad0d795b534dfe2c29de99cf9
author: Sam Leitch <sam@luceva.net>
date: Tue Jul 11 07:31:11 EDT 2017
Updated posix to include includes and optionally output files on test
--- a/.gitignore
+++ b/.gitignore
@@ -22,6 +22,8 @@
.DS_Store
ios/build/
ios/test/build/
+posix/include/
posix/bin/
posix/lib/
posix/obj/
+test/output/
--- a/posix/Rakefile
+++ b/posix/Rakefile
@@ -13,6 +13,8 @@
directory "obj"
directory "bin"
directory "lib"
+directory "include"
+directory "../test/output"
# Convert .c file in ../src to .o file in obj
rule ".o" => ->(o_file) {[o_file.gsub(/o$/, 'c').gsub("obj/", "../src/"), "obj"]} do |t|
@@ -22,25 +24,46 @@
# Use all .c files in the ../src directory
o_files = FileList["../src/*.c"].gsub(/c$/, 'o').gsub("../src/", "obj/")
+# Copy all .h files in the ../src directory
+h_files = FileList["../src/*.h"].gsub("../src/", "include/")
+
# Build static lib
file static_lib => o_files + ["lib"] do |t|
sh "#{AR} rcs #{static_lib} #{o_files.join(' ')}"
end
+# Copy header files
+rule /include\/.*\.h/ => ->(dst) { [dst.gsub("include/", "../src/"), "include"] } do |t|
+ FileUtils.cp t.source, t.name, :verbose => true
+end
+
+task :static_lib => h_files + [static_lib]
+
# Build test application
-file test_app => [static_lib, "test_h264bsd.c", "bin"] do |t|
- sh "#{CC} test_h264bsd.c -Llib -lh264bsd -o #{test_app}"
+file test_app => [:static_lib, "test_h264bsd.c", "bin"] do |t|
+ sh "#{CC} test_h264bsd.c #{CC_FLAGS} -Llib -lh264bsd -o #{test_app}"
end
# Run test application
-task :test => test_app do |t|
+task :test => [test_app] do |t|
sh "#{test_app} ../test/test_1920x1080.h264"
end
+# Run test application
+task :test_repeatedy => [test_app] do |t|
+ sh "#{test_app} -r ../test/test_1920x1080.h264"
+end
+
+# Run test application
+task :test_output => ["../test/output", test_app] do |t|
+ sh "#{test_app} -o ../test/output ../test/test_1920x1080.h264"
+end
+
task :clean do
FileUtils.rm_rf("obj")
FileUtils.rm_rf("bin")
FileUtils.rm_rf("lib")
+ FileUtils.rm_rf("include")
end
-task :default => [static_lib]
+task :default => [:static_lib]
--- a/posix/test_h264bsd.c
+++ b/posix/test_h264bsd.c
@@ -11,6 +11,9 @@
#include "../src/h264bsd_decoder.h"
#include "../src/h264bsd_util.h"
+static char* outputDir = NULL;
+static int repeatTest = 0;
+
void createContentBuffer(char* contentPath, u8** pContentBuffer, size_t* pContentSize) {
struct stat sb;
if (stat(contentPath, &sb) == -1) {
@@ -23,8 +26,8 @@
}
void loadContent(char* contentPath, u8* contentBuffer, size_t contentSize) {
- int fd = open(contentPath, O_RDONLY);
- if (fd == -1) {
+ FILE *input = fopen(contentPath, "r");
+ if (input == NULL) {
perror("open failed");
exit(1);
}
@@ -31,12 +34,33 @@
off_t offset = 0;
while(offset < contentSize) {
- offset += read(fd, contentBuffer + offset, contentSize - offset);
+ offset += fread(contentBuffer + offset, sizeof(u8), contentSize - offset, input);
}
- close(fd);
+ fclose(input);
}
+void saveImage(int picNum, u8* picData, int width, int height) {
+ if(!outputDir) return;
+
+ char outputPath[128];
+ sprintf(outputPath, "%s/frame_%02d.yuv", outputDir, picNum);
+
+ FILE *output = fopen(outputPath, "w");
+ if (output == NULL) {
+ perror("open failed");
+ exit(1);
+ }
+
+ size_t picSize = width * height * 3 / 2;
+ off_t offset = 0;
+ while(offset < picSize) {
+ offset += fwrite(picData + offset, sizeof(u8), picSize - offset, output);
+ }
+
+ fclose(output);
+}
+
void decodeContent(u8* contentBuffer, size_t contentSize) {
u32 status;
storage_t dec;
@@ -64,6 +88,7 @@
case H264BSD_PIC_RDY:
pic = h264bsdNextOutputPicture(&dec, &picId, &isIdrPic, &numErrMbs);
++numPics;
+ saveImage(numPics, pic, width, height);
break;
case H264BSD_HDRS_RDY:
h264bsdCroppingParams(&dec, &croppingFlag, &left, &width, &top, &height);
@@ -91,17 +116,37 @@
}
int main(int argc, char *argv[]) {
- if (argc != 2) {
- fprintf(stderr, "Usage: %s <pathname>\n", argv[0]);
+ int c = getopt (argc, argv, "ro:");
+ while (c != -1) {
+ switch (c) {
+ case 'o':
+ outputDir = optarg;
+ break;
+ case 'r':
+ repeatTest = 1;
+ break;
+ default:
+ abort ();
+ }
+ c = getopt (argc, argv, "o");
+ }
+
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s -r [-o <outputDir>] <test_video.h264>\n", argv[0]);
exit(1);
}
- char *contentPath = argv[1];
+ char *contentPath = argv[argc - 1];
u8* contentBuffer;
size_t contentSize;
createContentBuffer(contentPath, &contentBuffer, &contentSize);
- for(int i=0; i<10; ++i) {
+ if (repeatTest) {
+ while(1) {
+ loadContent(contentPath, contentBuffer, contentSize);
+ decodeContent(contentBuffer, contentSize);
+ }
+ } else {
loadContent(contentPath, contentBuffer, contentSize);
decodeContent(contentBuffer, contentSize);
}