#include <gst/gst.h>
#include <glib.h>
#include <iostream>
#include <fstream>
#include <vector>
GstFlowReturn new_sample (GstElement *sink, std::vector<char>* data) {
GstSample *sample;
g_signal_emit_by_name (sink, "pull-sample", &sample);
if (sample) {
GstBuffer *buffer = gst_sample_get_buffer(sample);
gst_buffer_fill(buffer, 0, data->data(), data->size());
gst_sample_unref(sample);
return GST_FLOW_OK;
}
return GST_FLOW_ERROR;
}
int main(int argc, char *argv[]) {
GstElement *pipeline, *appsrc;
/* Initialize GStreamer */
gst_init (&argc, &argv);
/* Build the pipeline */
std::string pipeline_str = "appsrc name=source ! video/quicktime ! decodebin ! videoconvert ! autovideosink";
pipeline = gst_parse_launch(pipeline_str.c_str(), NULL);
/* Setup appsrc */
appsrc = gst_bin_get_by_name(GST_BIN(pipeline), "source");
if(!appsrc) {
std::cout << "Unable to get appsrc" << std::endl;
return -1;
}
/* Read data into buffer */
std::ifstream file("file.mp4", std::ios::binary);
std::vector<char> buffer((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
/* Setup necessary signals */
g_signal_connect(appsrc, "need-data", (GCallback)new_sample, &buffer);
/* Start playing */
gst_app_src_set_size((GstAppSrc*) appsrc, buffer.size());
gst_element_set_state(pipeline, GST_STATE_PLAYING);
/* Wait until error or EOS */
GstBus *bus;
GstMessage *msg;
bus = gst_element_get_bus(pipeline);
msg = gst_bus_timed_pop_filtered(bus, GST_CLOCK_TIME_NONE, (GstMessageType)(GST_MESSAGE_ERROR | GST_MESSAGE_EOS));
/* Free resources */
if (msg != NULL)
gst_message_unref(msg);
gst_object_unref(bus);
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(pipeline);
return 0;
}
template<typename T,size_t RowNum, size_t ColNum>
class Array2D {
private:
T arr[RowNum*ColNum];
public:
class Proxy
{
private:
T* _arr;
public:
Proxy(T arr[]) : _arr(arr) {}
T& operator[](size_t index)
{
return _arr[index];
}
};
Proxy operator[](size_t index)
{
return Proxy(&arr[index*ColNum]);
}
};
typedef Array2D<int, 3, 5> mas35;
mas35 test()
{
return *(new mas35); // с этим нужно быть предельно осторожным, так как бездумно можно получить утечки памяти
}
int main()
{
mas35 a=test();
a[1][0] = 5;
// ...
return 0;
}
// можно
выражение++
// но нельзя
выражение+
// можно
+выражение
MyClass operator+()
{
// выполнить действия с this
return MyClass(value);
}
(nujno==+)
никак нельзя сделать валидным (препроцессор кстати тоже не позволит переопределить поведение +), да и == - бинарный оператор (нет варианта с его одинарным использованием) static vnet_feature_arc_registration_t vnet_feat_arc_ip4_unicast;
static void __vnet_add_feature_arc_registration_ip4_unicast (void)
__attribute__((__constructor__)) ;
static void __vnet_add_feature_arc_registration_ip4_unicast (void)
{
vnet_feature_main_t * fm = &feature_main;
vnet_feat_arc_ip4_unicast.next = fm->next_arc;
fm->next_arc = & vnet_feat_arc_ip4_unicast;
}
static void __vnet_rm_feature_arc_registration_ip4_unicast (void)
__attribute__((__destructor__)) ;
static void __vnet_rm_feature_arc_registration_ip4_unicast (void)
{
vnet_feature_main_t * fm = &feature_main;
vnet_feature_arc_registration_t *r = &vnet_feat_arc_ip4_unicast;
VLIB_REMOVE_FROM_LINKED_LIST (fm->next_arc, r, next);
}
static vnet_feature_arc_registration_t vnet_feat_arc_ip4_unicast
{ .имя_поля=значение,...}
это удобный способ инициализировать структуры Как скрыть адрес вызываемой функции в C++?в контексте обфускации, подразумевается что по декомпилированному исходному коду должно быть не ясно, какой именно метод будет вызываться (т.е. для анализа требуется отладка, что сложнее/дороже), значит хранить адреса методов нужно в каких то переменных, например массивах, а выбор следующего вызываемого метода делать на основе каких то вычислений по коду.
// определяем класс
class MyClass
{
public:
void myFunA(){std::cout<<"A";};
void myFunB(){std::cout<<"B";};
};
std::function<void(MyClass*)> functions[]={&MyClass::myFunA,&MyClass::myFunB};
MyClass obj;
functions[x](&obj);
#pragma once
template<int SIZE> struct MyStruct {
int a;
char buf[SIZE];
};
...
auto x=new MyStruct<10>; // x - указатель на MyStruct
или
const int size=10;
auto x=new MyStruct<size>;
...
delete x;
temlate <typename Derived1Enum> inline void Derived1::_someMethod(const Derived1Enum _state) {
...одинаковый код...
state = _state
...одинаковый код...
}
void Derived1::someMethod() {
_someMethod(Derived1Enum::SomeStateDerived1)
}
void Derived2::someMethod() {
_someMethod(Derived2Enum::SomeStateDerived2)
}