Commit 80577dff authored by Paul Wilkins's avatar Paul Wilkins

Revert "Changing webmenc to use libwebm"

Temporary revert.
Problems with conflicting definitions of type off_t
in MSVC builds that need resolving.

c:\Program Files (x86)\
  Microsoft Visual Studio 9.0\VC\include\wchar.h(479) :
  "error C2371: 'off_t' : redefinition; different basic types
c:\on2experimental\libvpx\tools_common.h(26) :
   see declaration of 'off_t'"

This reverts commit 92a4c591.

Change-Id: I535e40a18842a92e3e6e0b29e5fba66313010803
parent 88690475
......@@ -147,15 +147,6 @@ $(BUILD_PFX)%.cc.o: %.cc
$(if $(quiet),@echo " [CXX] $@")
$(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -c -o $@ $<
$(BUILD_PFX)%.cpp.d: %.cpp
$(if $(quiet),@echo " [DEP] $@")
$(qexec)mkdir -p $(dir $@)
$(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -M $< | $(fmt_deps) > $@
$(BUILD_PFX)%.cpp.o: %.cpp
$(if $(quiet),@echo " [CXX] $@")
$(qexec)$(CXX) $(INTERNAL_CFLAGS) $(CXXFLAGS) -c -o $@ $<
$(BUILD_PFX)%.asm.d: %.asm
$(if $(quiet),@echo " [DEP] $@")
$(qexec)mkdir -p $(dir $@)
......@@ -227,7 +218,7 @@ cond_enabled=$(if $(filter yes,$($(1))), $(call enabled,$(2)))
find_file1=$(word 1,$(wildcard $(subst //,/,$(addsuffix /$(1),$(2)))))
find_file=$(foreach f,$(1),$(call find_file1,$(strip $(f)),$(strip $(2))) )
obj_pats=.c=.c.o $(AS_SFX)=$(AS_SFX).o .cc=.cc.o .cpp=.cpp.o
obj_pats=.c=.c.o $(AS_SFX)=$(AS_SFX).o .cc=.cc.o
objs=$(addprefix $(BUILD_PFX),$(foreach p,$(obj_pats),$(filter %.o,$(1:$(p))) ))
install_map_templates=$(eval $(call install_map_template,$(1),$(2)))
......
......@@ -704,11 +704,13 @@ process_toolchain() {
enabled postproc || die "postproc_visualizer requires postproc to be enabled"
fi
# Enable WebM IO by default.
soft_enable webm_io
# Enable unit tests by default if we have a working C++ compiler.
case "$toolchain" in
*-vs*)
soft_enable unit_tests
soft_enable webm_io
;;
*-android-*)
# GTestLog must be modified to use Android logging utilities.
......@@ -723,22 +725,14 @@ process_toolchain() {
# would be disabled for the same reason.
check_cxx "$@" <<EOF && soft_enable unit_tests
int z;
EOF
check_cxx "$@" <<EOF && soft_enable webm_io
int z;
EOF
;;
*)
enabled pthread_h && check_cxx "$@" <<EOF && soft_enable unit_tests
int z;
EOF
check_cxx "$@" <<EOF && soft_enable webm_io
int z;
EOF
;;
esac
# libwebm needs to be linked with C++ standard library
enabled webm_io && LD=${CXX}
}
......
......@@ -15,16 +15,6 @@ LIBYUV_SRCS += third_party/libyuv/include/libyuv/basic_types.h \
third_party/libyuv/source/scale.c \
third_party/libyuv/source/cpu_id.c
LIBWEBM_MUXER_SRCS += third_party/libwebm/mkvmuxer.cpp \
third_party/libwebm/mkvmuxerutil.cpp \
third_party/libwebm/mkvwriter.cpp \
third_party/libwebm/mkvmuxer.hpp \
third_party/libwebm/mkvmuxertypes.hpp \
third_party/libwebm/mkvmuxerutil.hpp \
third_party/libwebm/mkvparser.hpp \
third_party/libwebm/mkvwriter.hpp \
third_party/libwebm/webmids.hpp
# List of examples to build. UTILS are tools meant for distribution
# while EXAMPLES demonstrate specific portions of the API.
UTILS-$(CONFIG_DECODERS) += vpxdec.c
......@@ -63,8 +53,10 @@ vpxenc.SRCS += vpx_ports/vpx_timer.h
vpxenc.SRCS += vpxstats.c vpxstats.h
vpxenc.SRCS += $(LIBYUV_SRCS)
ifeq ($(CONFIG_WEBM_IO),yes)
vpxenc.SRCS += $(LIBWEBM_MUXER_SRCS)
vpxenc.SRCS += webmenc.cc webmenc.h
vpxenc.SRCS += third_party/libmkv/EbmlIDs.h
vpxenc.SRCS += third_party/libmkv/EbmlWriter.c
vpxenc.SRCS += third_party/libmkv/EbmlWriter.h
vpxenc.SRCS += webmenc.c webmenc.h
endif
vpxenc.GUID = 548DEC74-7A15-4B2B-AFC3-AA102E7C25C1
vpxenc.DESCRIPTION = Full featured encoder
......
......@@ -123,6 +123,55 @@ int fourcc_is_ivf(const char detect[4]) {
return 0;
}
#if CONFIG_WEBM_IO
/* Murmur hash derived from public domain reference implementation at
* http:// sites.google.com/site/murmurhash/
*/
static unsigned int murmur(const void *key, int len, unsigned int seed) {
const unsigned int m = 0x5bd1e995;
const int r = 24;
unsigned int h = seed ^ len;
const unsigned char *data = (const unsigned char *)key;
while (len >= 4) {
unsigned int k;
k = (unsigned int)data[0];
k |= (unsigned int)data[1] << 8;
k |= (unsigned int)data[2] << 16;
k |= (unsigned int)data[3] << 24;
k *= m;
k ^= k >> r;
k *= m;
h *= m;
h ^= k;
data += 4;
len -= 4;
}
switch (len) {
case 3:
h ^= data[2] << 16;
case 2:
h ^= data[1] << 8;
case 1:
h ^= data[0];
h *= m;
};
h ^= h >> 13;
h *= m;
h ^= h >> 15;
return h;
}
#endif // CONFIG_WEBM_IO
static const arg_def_t debugmode = ARG_DEF("D", "debug", 0,
"Debug mode (makes output deterministic)");
static const arg_def_t outputfile = ARG_DEF("o", "output", 1,
......@@ -565,6 +614,7 @@ struct stream_state {
FILE *file;
struct rate_hist *rate_hist;
struct EbmlGlobal ebml;
uint32_t hash;
uint64_t psnr_sse_total;
uint64_t psnr_samples_total;
double psnr_totals[4];
......@@ -786,9 +836,7 @@ static struct stream_state *new_stream(struct VpxEncoderConfig *global,
stream->config.stereo_fmt = STEREO_FORMAT_MONO;
stream->config.write_webm = 1;
#if CONFIG_WEBM_IO
stream->ebml.last_pts_ns = -1;
stream->ebml.writer = NULL;
stream->ebml.segment = NULL;
stream->ebml.last_pts_ms = -1;
#endif
/* Allows removal of the application version from the EBML tags */
......@@ -1123,7 +1171,9 @@ static void close_output_file(struct stream_state *stream,
#if CONFIG_WEBM_IO
if (stream->config.write_webm) {
write_webm_file_footer(&stream->ebml);
write_webm_file_footer(&stream->ebml, stream->hash);
free(stream->ebml.cue_list);
stream->ebml.cue_list = NULL;
}
#endif
......@@ -1279,6 +1329,12 @@ static void get_cx_data(struct stream_state *stream,
update_rate_histogram(stream->rate_hist, cfg, pkt);
#if CONFIG_WEBM_IO
if (stream->config.write_webm) {
/* Update the hash */
if (!stream->ebml.debug)
stream->hash = murmur(pkt->data.frame.buf,
(int)pkt->data.frame.sz,
stream->hash);
write_webm_block(&stream->ebml, cfg, pkt);
}
#endif
......
This diff is collapsed.
/*
* Copyright (c) 2014 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "./webmenc.h"
#include <string>
#include "third_party/libwebm/mkvmuxer.hpp"
#include "third_party/libwebm/mkvmuxerutil.hpp"
#include "third_party/libwebm/mkvwriter.hpp"
namespace {
const uint64_t kDebugTrackUid = 0xDEADBEEF;
const int kVideoTrackNumber = 1;
} // namespace
void write_webm_file_header(struct EbmlGlobal *glob,
const vpx_codec_enc_cfg_t *cfg,
const struct vpx_rational *fps,
stereo_format_t stereo_fmt,
unsigned int fourcc) {
mkvmuxer::MkvWriter *const writer = new mkvmuxer::MkvWriter(glob->stream);
mkvmuxer::Segment *const segment = new mkvmuxer::Segment();
segment->Init(writer);
segment->set_mode(mkvmuxer::Segment::kFile);
segment->OutputCues(true);
mkvmuxer::SegmentInfo *const info = segment->GetSegmentInfo();
const uint64_t kTimecodeScale = 1000000;
info->set_timecode_scale(kTimecodeScale);
std::string version = "vpxenc";
if (!glob->debug) {
version.append(std::string(" ") + vpx_codec_version_str());
}
info->set_writing_app(version.c_str());
const int video_track_id = segment->AddVideoTrack(static_cast<int>(cfg->g_w),
static_cast<int>(cfg->g_h),
kVideoTrackNumber);
mkvmuxer::VideoTrack* const video_track =
static_cast<mkvmuxer::VideoTrack*>(
segment->GetTrackByNumber(video_track_id));
video_track->SetStereoMode(stereo_fmt);
video_track->set_codec_id(fourcc == VP8_FOURCC ? "V_VP8" : "V_VP9");
if (glob->debug) {
video_track->set_uid(kDebugTrackUid);
}
glob->writer = writer;
glob->segment = segment;
}
void write_webm_block(struct EbmlGlobal *glob,
const vpx_codec_enc_cfg_t *cfg,
const vpx_codec_cx_pkt_t *pkt) {
mkvmuxer::Segment *const segment =
reinterpret_cast<mkvmuxer::Segment*>(glob->segment);
int64_t pts_ns = pkt->data.frame.pts * 1000000000ll *
cfg->g_timebase.num / cfg->g_timebase.den;
if (pts_ns <= glob->last_pts_ns)
pts_ns = glob->last_pts_ns + 1000000;
glob->last_pts_ns = pts_ns;
segment->AddFrame(static_cast<uint8_t*>(pkt->data.frame.buf),
pkt->data.frame.sz,
kVideoTrackNumber,
pts_ns,
pkt->data.frame.flags & VPX_FRAME_IS_KEY);
}
void write_webm_file_footer(struct EbmlGlobal *glob) {
mkvmuxer::MkvWriter *const writer =
reinterpret_cast<mkvmuxer::MkvWriter*>(glob->writer);
mkvmuxer::Segment *const segment =
reinterpret_cast<mkvmuxer::Segment*>(glob->segment);
segment->Finalize();
delete segment;
delete writer;
glob->writer = NULL;
glob->segment = NULL;
}
......@@ -13,6 +13,13 @@
#include <stdio.h>
#include <stdlib.h>
#if defined(_MSC_VER)
/* MSVS doesn't define off_t */
typedef __int64 off_t;
#else
#include <stdint.h>
#endif
#include "tools_common.h"
#include "vpx/vpx_encoder.h"
......@@ -20,13 +27,40 @@
extern "C" {
#endif
/* TODO(vigneshv): Rename this struct */
typedef off_t EbmlLoc;
struct cue_entry {
unsigned int time;
uint64_t loc;
};
struct EbmlGlobal {
int debug;
FILE *stream;
int64_t last_pts_ns;
void *writer;
void *segment;
int64_t last_pts_ms;
vpx_rational_t framerate;
/* These pointers are to the start of an element */
off_t position_reference;
off_t seek_info_pos;
off_t segment_info_pos;
off_t track_pos;
off_t cue_pos;
off_t cluster_pos;
/* This pointer is to a specific element to be serialized */
off_t track_id_pos;
/* These pointers are to the size field of the element */
EbmlLoc startSegment;
EbmlLoc startCluster;
uint32_t cluster_timecode;
int cluster_open;
struct cue_entry *cue_list;
unsigned int cues;
};
/* Stereo 3D packed frame format */
......@@ -38,6 +72,10 @@ typedef enum stereo_format {
STEREO_FORMAT_RIGHT_LEFT = 11
} stereo_format_t;
void write_webm_seek_element(struct EbmlGlobal *ebml,
unsigned int id,
off_t pos);
void write_webm_file_header(struct EbmlGlobal *glob,
const vpx_codec_enc_cfg_t *cfg,
const struct vpx_rational *fps,
......@@ -48,7 +86,7 @@ void write_webm_block(struct EbmlGlobal *glob,
const vpx_codec_enc_cfg_t *cfg,
const vpx_codec_cx_pkt_t *pkt);
void write_webm_file_footer(struct EbmlGlobal *glob);
void write_webm_file_footer(struct EbmlGlobal *glob, int hash);
#ifdef __cplusplus
} // extern "C"
......
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