Commit 501370ae authored by Manuel Günther's avatar Manuel Günther
Browse files

Updated Video Reader bindings (writer still missing)

parent ad7d77a4
......@@ -15,8 +15,7 @@
#include <bob.core/api.h>
#include <bob.io.base/api.h>
#include "file.h"
#include "cpp/utils.h"
#include "main.h"
extern "C" {
......@@ -603,37 +602,26 @@ static PyModuleDef module_definition = {
};
#endif
extern PyTypeObject PyBobIoVideoReader_Type;
extern PyTypeObject PyBobIoVideoReaderIterator_Type;
extern PyTypeObject PyBobIoVideoWriter_Type;
static PyObject* create_module (void) {
PyBobIoVideoReader_Type.tp_new = PyType_GenericNew;
if (PyType_Ready(&PyBobIoVideoReader_Type) < 0) return 0;
PyBobIoVideoReaderIterator_Type.tp_new = PyType_GenericNew;
if (PyType_Ready(&PyBobIoVideoReaderIterator_Type) < 0) return 0;
PyBobIoVideoWriter_Type.tp_new = PyType_GenericNew;
if (PyType_Ready(&PyBobIoVideoWriter_Type) < 0) return 0;
# if PY_VERSION_HEX >= 0x03000000
PyObject* m = PyModule_Create(&module_definition);
auto m_ = make_xsafe(m);
PyObject* module = PyModule_Create(&module_definition);
auto module_ = make_xsafe(module);
const char* ret = "O";
# else
PyObject* m = Py_InitModule3(BOB_EXT_MODULE_NAME, module_methods, module_docstr);
PyObject* module = Py_InitModule3(BOB_EXT_MODULE_NAME, module_methods, module_docstr);
const char* ret = "N";
# endif
if (!m) return 0;
if (!module) return 0;
/* register the types to python */
Py_INCREF(&PyBobIoVideoReader_Type);
if (PyModule_AddObject(m, "reader", (PyObject *)&PyBobIoVideoReader_Type) < 0) return 0;
if (!init_BobIoVideoReader(module)) return 0;
Py_INCREF(&PyBobIoVideoWriter_Type);
if (PyModule_AddObject(m, "writer", (PyObject *)&PyBobIoVideoWriter_Type) < 0) return 0;
if (PyModule_AddObject(module, "writer", (PyObject *)&PyBobIoVideoWriter_Type) < 0) return 0;
/* imports dependencies */
if (import_bob_blitz() < 0) return 0;
......@@ -650,7 +638,7 @@ static PyObject* create_module (void) {
}
}
return Py_BuildValue(ret, m);
return Py_BuildValue(ret, module);
}
PyMODINIT_FUNC BOB_EXT_ENTRY_NAME (void) {
......
/**
* @author Manuel Guenther <siebenkopf@googlemail.com>
* @date Wed Jun 7 17:24:09 MDT 2017
*
* @brief Header file for bindings to bob::io::video
*/
#ifndef BOB_IO_VIDEO_MAIN_H
#define BOB_IO_VIDEO_MAIN_H
#include <bob.blitz/cppapi.h>
#include <bob.blitz/cleanup.h>
#include <bob.core/api.h>
#include <bob.io.base/api.h>
#include <bob.extension/documentation.h>
#include "cpp/utils.h"
#include "cpp/reader.h"
#include "cpp/writer.h"
#include "bobskin.h"
#include "file.h"
// Reader
typedef struct {
PyObject_HEAD
boost::shared_ptr<bob::io::video::Reader> v;
} PyBobIoVideoReaderObject;
extern PyTypeObject PyBobIoVideoReader_Type;
bool init_BobIoVideoReader(PyObject* module);
int PyBobIoVideoReader_Check(PyObject* o);
// Iterator
typedef struct {
PyObject_HEAD
PyBobIoVideoReaderObject* pyreader;
boost::shared_ptr<bob::io::video::Reader::const_iterator> iter;
} PyBobIoVideoReaderIteratorObject;
extern PyTypeObject PyBobIoVideoReaderIterator_Type;
// Writer
typedef struct {
PyObject_HEAD
boost::shared_ptr<bob::io::video::Writer> v;
} PyBobIoVideoWriterObject;
extern PyTypeObject PyBobIoVideoWriter_Type;
bool init_BobIoVideoWriter(PyObject* module);
int PyBobIoVideoWriter_Check(PyObject* o);
#endif // BOB_IO_VIDEO_MAIN_H
This diff is collapsed.
......@@ -11,7 +11,7 @@
import os
import numpy
import nose.tools
from . import test_utils
from bob.io.video import test_utils
from bob.io.base import load
......@@ -21,7 +21,7 @@ INPUT_VIDEO = test_utils.datafile('test.mov', __name__)
def test_codec_support():
# Describes all encoders
from . import describe_encoder, describe_decoder, supported_video_codecs
from bob.io.video import describe_encoder, describe_decoder, supported_video_codecs
supported = supported_video_codecs()
......@@ -39,7 +39,7 @@ def test_codec_support():
def test_input_format_support():
# Describes all encoders
from . import supported_videoreader_formats
from bob.io.video import supported_videoreader_formats
supported = supported_videoreader_formats()
......@@ -50,7 +50,7 @@ def test_input_format_support():
def test_output_format_support():
# Describes all encoders
from . import supported_videowriter_formats
from bob.io.video import supported_videowriter_formats
supported = supported_videowriter_formats()
......@@ -60,7 +60,7 @@ def test_output_format_support():
def test_video_reader_attributes():
from . import reader
from bob.io.video import reader
iv = reader(INPUT_VIDEO)
......@@ -89,7 +89,7 @@ def test_video_reader_attributes():
def test_video_reader_str():
from . import reader
from bob.io.video import reader
iv = reader(INPUT_VIDEO)
assert repr(iv)
......@@ -97,7 +97,7 @@ def test_video_reader_str():
def test_can_iterate():
from . import reader
from bob.io.video import reader
video = reader(INPUT_VIDEO)
counter = 0
for frame in video:
......@@ -112,7 +112,7 @@ def test_can_iterate():
def test_iteration():
from . import reader
from bob.io.video import reader
f = reader(INPUT_VIDEO)
objs = load(INPUT_VIDEO)
......@@ -122,7 +122,7 @@ def test_iteration():
def test_indexing():
from . import reader
from bob.io.video import reader
f = reader(INPUT_VIDEO)
nose.tools.eq_(len(f), 375)
......@@ -140,7 +140,7 @@ def test_indexing():
def test_slicing_empty():
from . import reader
from bob.io.video import reader
f = reader(INPUT_VIDEO)
objs = f[1:1]
......@@ -149,7 +149,7 @@ def test_slicing_empty():
def test_slicing_0():
from . import reader
from bob.io.video import reader
f = reader(INPUT_VIDEO)
objs = f[:]
......@@ -158,7 +158,7 @@ def test_slicing_0():
def test_slicing_1():
from . import reader
from bob.io.video import reader
f = reader(INPUT_VIDEO)
s = f[3:10:2]
......@@ -170,7 +170,7 @@ def test_slicing_1():
def test_slicing_2():
from . import reader
from bob.io.video import reader
f = reader(INPUT_VIDEO)
s = f[-10:-2:3]
......@@ -181,7 +181,7 @@ def test_slicing_2():
def test_slicing_3():
from . import reader
from bob.io.video import reader
f = reader(INPUT_VIDEO)
objs = f.load()
......@@ -195,7 +195,7 @@ def test_slicing_3():
def test_slicing_4():
from . import reader
from bob.io.video import reader
f = reader(INPUT_VIDEO)
objs = f[:21]
......@@ -210,7 +210,7 @@ def test_slicing_4():
def test_can_use_array_interface():
from . import reader
from bob.io.video import reader
array = load(INPUT_VIDEO)
iv = reader(INPUT_VIDEO)
......@@ -219,10 +219,10 @@ def test_can_use_array_interface():
def test_video_reading_after_writing():
from . import test_utils
from bob.io.video import test_utils
tmpname = test_utils.temporary_filename(suffix='.avi')
from . import writer, reader
from bob.io.video import writer, reader
try:
......@@ -248,10 +248,10 @@ def test_video_reading_after_writing():
def test_video_writer_close():
from . import test_utils
from bob.io.video import test_utils
tmpname = test_utils.temporary_filename(suffix='.avi')
from . import writer, reader
from bob.io.video import writer, reader
try:
......@@ -281,10 +281,10 @@ def test_video_writer_close():
def test_closed_video_writer_raises():
from . import test_utils
from bob.io.video import test_utils
tmpname = test_utils.temporary_filename(suffix='.avi')
from . import writer
from bob.io.video import writer
try:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment