Skip to content

Commit

Permalink
Merge pull request tensorflow#119 from yongtang/dlopen
Browse files Browse the repository at this point in the history
Fix tiff lib and remove stub ffmpeg libraries for macOS support
  • Loading branch information
terrytangyuan committed Feb 25, 2019
2 parents b3c43db + 5920c24 commit 67de8a8
Show file tree
Hide file tree
Showing 17 changed files with 53 additions and 49 deletions.
1 change: 0 additions & 1 deletion .travis/build.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ fi
bazel build \
--noshow_progress \
--noshow_loading_progress \
--spawn_strategy standalone \
--verbose_failures \
--test_output=errors -- \
//tensorflow_io/...
Expand Down
1 change: 0 additions & 1 deletion .travis/python.release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ fi
bazel build \
--noshow_progress \
--noshow_loading_progress \
--spawn_strategy standalone \
--verbose_failures \
--test_output=errors -- \
//tensorflow_io/...
Expand Down
43 changes: 6 additions & 37 deletions tensorflow_io/video/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ licenses(["notice"]) # Apache 2.0

package(default_visibility = ["//visibility:public"])

# Note: stub files are generated from Ubuntu 14.0 with
# `echo '' | g++ -shared -fPIC -x c++ - -o $@`
filegroup(
name = "stub.so",
srcs = glob(["kernel/stub/*"]),
)

cc_binary(
name = 'python/ops/_video_ops_ffmpeg_3.4.so',
srcs = [
Expand All @@ -19,21 +12,13 @@ cc_binary(
],
includes = ["."],
linkshared = 1,
linkopts = [
"-Ltensorflow_io/video/kernels/stub",
"-l:libavformat.so.57",
"-l:libavcodec.so.57",
"-l:libavutil.so.55",
"-l:libswscale.so.4",
],
linkopts = [],
deps = [
"@local_config_tf//:libtensorflow_framework",
"@local_config_tf//:tf_header_lib",
"@ffmpeg_3_4//:ffmpeg",
],
data = [
":stub.so",
],
data = [],
copts = ["-pthread", "-std=c++11", "-D_GLIBCXX_USE_CXX11_ABI=0", "-DNDEBUG"]
)

Expand All @@ -47,21 +32,13 @@ cc_binary(
],
includes = ["."],
linkshared = 1,
linkopts = [
"-Ltensorflow_io/video/kernels/stub",
"-l:libavformat-ffmpeg.so.56",
"-l:libavcodec-ffmpeg.so.56",
"-l:libavutil-ffmpeg.so.54",
"-l:libswscale-ffmpeg.so.3",
],
linkopts = [],
deps = [
"@local_config_tf//:libtensorflow_framework",
"@local_config_tf//:tf_header_lib",
"@ffmpeg_2_8//:ffmpeg",
],
data = [
":stub.so",
],
data = [],
copts = ["-pthread", "-std=c++11", "-D_GLIBCXX_USE_CXX11_ABI=0", "-DNDEBUG"]
)

Expand All @@ -75,20 +52,12 @@ cc_binary(
],
includes = ["."],
linkshared = 1,
linkopts = [
"-Ltensorflow_io/video/kernels/stub",
"-l:libavformat.so.54",
"-l:libavcodec.so.54",
"-l:libavutil.so.52",
"-l:libswscale.so.2",
],
linkopts = [],
deps = [
"@local_config_tf//:libtensorflow_framework",
"@local_config_tf//:tf_header_lib",
"@libav_9_20//:libav",
],
data = [
":stub.so",
],
data = [],
copts = ["-pthread", "-std=c++11", "-D_GLIBCXX_USE_CXX11_ABI=0", "-DNDEBUG"]
)
Binary file not shown.
Binary file removed tensorflow_io/video/kernels/stub/libavcodec.so.54
Binary file not shown.
Binary file removed tensorflow_io/video/kernels/stub/libavcodec.so.57
Binary file not shown.
Binary file not shown.
Binary file removed tensorflow_io/video/kernels/stub/libavformat.so.54
Binary file not shown.
Binary file removed tensorflow_io/video/kernels/stub/libavformat.so.57
Binary file not shown.
Binary file not shown.
Binary file removed tensorflow_io/video/kernels/stub/libavutil.so.52
Binary file not shown.
Binary file removed tensorflow_io/video/kernels/stub/libavutil.so.55
Binary file not shown.
Binary file not shown.
Binary file removed tensorflow_io/video/kernels/stub/libswscale.so.2
Binary file not shown.
Binary file removed tensorflow_io/video/kernels/stub/libswscale.so.4
Binary file not shown.
50 changes: 43 additions & 7 deletions tensorflow_io/video/python/ops/video_dataset_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,56 @@
from __future__ import print_function

import os
import ctypes
import _ctypes

import tensorflow
from tensorflow import dtypes
from tensorflow import errors
from tensorflow.compat.v1 import data
from tensorflow_io import _load_library
video_ops = None
for f in ['_video_ops_ffmpeg_3.4.so', '_video_ops_ffmpeg_2.8.so', '_video_ops_libav_9.20.so']:
try:
video_ops = _load_library(f)
break;
except NotImplementedError as e:
print(e)

def load_dependency_and_library(p):
for library in p:
# First try load all dependencies with RTLD_LOCAL
entries = []
for dependency in p[library]:
try:
entries.append(ctypes.CDLL(dependency))
except OSError as e:
pass
if len(entries) == len(p[library]):
# Dependencies has been satisfied, load dependencies again with RTLD_GLOBAL, no error is expected
for dependency in p[library]:
ctypes.CDLL(dependency, mode=ctypes.RTLD_GLOBAL)
# Load video_op
return _load_library(library)
# Otherwise we dlclose and retry
entries.reverse()
for entry in entries:
_ctypes.dlclose(entry._handle)
raise NotImplementedError("could not find ffmpeg after search through ", p)

video_ops = load_dependency_and_library({
'_video_ops_ffmpeg_3.4.so' : [
"libavformat.so.57",
"libavformat.so.57",
"libavutil.so.55",
"libswscale.so.4",
],
'_video_ops_ffmpeg_2.8.so' : [
"libavformat-ffmpeg.so.56",
"libavcodec-ffmpeg.so.56",
"libavutil-ffmpeg.so.54",
"libswscale-ffmpeg.so.3",
],
'_video_ops_libav_9.20.so' : [
"libavformat.so.54",
"libavcodec.so.54",
"libavutil.so.52",
"libswscale.so.2",
],
})

class VideoDataset(data.Dataset):
"""A Video File Dataset that reads the video file."""
Expand Down
7 changes: 4 additions & 3 deletions third_party/libtiff.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ cc_library(
exclude=[
"libtiff/tif_win32.c",
]),
hdrs = [
"libtiff/tiff.h",
"libtiff/tiffconf.h",
hdrs = glob([
"libtiff/*.h",
]) + [
"libtiff/tif_config.h",
"libtiff/tiffconf.h",
],
copts = [
"-D_GLIBCXX_USE_CXX11_ABI=0",
Expand Down

0 comments on commit 67de8a8

Please sign in to comment.