
Recherche avancée
Médias (91)
-
Richard Stallman et le logiciel libre
19 octobre 2011, par
Mis à jour : Mai 2013
Langue : français
Type : Texte
-
Stereo master soundtrack
17 octobre 2011, par
Mis à jour : Octobre 2011
Langue : English
Type : Audio
-
Elephants Dream - Cover of the soundtrack
17 octobre 2011, par
Mis à jour : Octobre 2011
Langue : English
Type : Image
-
#7 Ambience
16 octobre 2011, par
Mis à jour : Juin 2015
Langue : English
Type : Audio
-
#6 Teaser Music
16 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
-
#5 End Title
16 octobre 2011, par
Mis à jour : Février 2013
Langue : English
Type : Audio
Autres articles (84)
-
Le profil des utilisateurs
12 avril 2011, parChaque utilisateur dispose d’une page de profil lui permettant de modifier ses informations personnelle. Dans le menu de haut de page par défaut, un élément de menu est automatiquement créé à l’initialisation de MediaSPIP, visible uniquement si le visiteur est identifié sur le site.
L’utilisateur a accès à la modification de profil depuis sa page auteur, un lien dans la navigation "Modifier votre profil" est (...) -
Configurer la prise en compte des langues
15 novembre 2010, parAccéder à la configuration et ajouter des langues prises en compte
Afin de configurer la prise en compte de nouvelles langues, il est nécessaire de se rendre dans la partie "Administrer" du site.
De là, dans le menu de navigation, vous pouvez accéder à une partie "Gestion des langues" permettant d’activer la prise en compte de nouvelles langues.
Chaque nouvelle langue ajoutée reste désactivable tant qu’aucun objet n’est créé dans cette langue. Dans ce cas, elle devient grisée dans la configuration et (...) -
MediaSPIP Init et Diogène : types de publications de MediaSPIP
11 novembre 2010, parÀ l’installation d’un site MediaSPIP, le plugin MediaSPIP Init réalise certaines opérations dont la principale consiste à créer quatre rubriques principales dans le site et de créer cinq templates de formulaire pour Diogène.
Ces quatre rubriques principales (aussi appelées secteurs) sont : Medias ; Sites ; Editos ; Actualités ;
Pour chacune de ces rubriques est créé un template de formulaire spécifique éponyme. Pour la rubrique "Medias" un second template "catégorie" est créé permettant d’ajouter (...)
Sur d’autres sites (6861)
-
Ogg objections
3 mars 2010, par Mans — MultimediaThe Ogg container format is being promoted by the Xiph Foundation for use with its Vorbis and Theora codecs. Unfortunately, a number of technical shortcomings in the format render it ill-suited to most, if not all, use cases. This article examines the most severe of these flaws.
Overview of Ogg
The basic unit in an Ogg stream is the page consisting of a header followed by one or more packets from a single elementary stream. A page can contain up to 255 packets, and a packet can span any number of pages. The following table describes the page header.
Field Size (bits) Description capture_pattern 32 magic number “OggS” version 8 always zero flags 8 granule_position 64 abstract timestamp bitstream_serial_number 32 elementary stream number page_sequence_number 32 incremented by 1 each page checksum 32 CRC of entire page page_segments 8 length of segment_table segment_table variable list of packet sizes Elementary stream types are identified by looking at the payload of the first few pages, which contain any setup data required by the decoders. For full details, see the official format specification.
Generality
Ogg, legend tells, was designed to be a general-purpose container format. To most multimedia developers, a general-purpose format is one in which encoded data of any type can be encapsulated with a minimum of effort.
The Ogg format defined by the specification does not fit this description. For every format one wishes to use with Ogg, a complex mapping must first be defined. This mapping defines how to identify a codec, how to extract setup data, and even how timestamps are to be interpreted. All this is done differently for every codec. To correctly parse an Ogg stream, every such mapping ever defined must be known.
Under this premise, a centralised repository of codec mappings would seem like a sensible idea, but alas, no such thing exists. It is simply impossible to obtain a exhaustive list of defined mappings, which makes the task of creating a complete implementation somewhat daunting.
One brave soul, Tobias Waldvogel, created a mapping, OGM, capable of storing any Microsoft AVI compatible codec data in Ogg files. This format saw some use in the wild, but was frowned upon by Xiph, and it was eventually displaced by other formats.
True generality is evidently not to be found with the Ogg format.
A good example of a general-purpose format is Matroska. This container can trivially accommodate any codec, all it requires is a unique string to identify the codec. For codecs requiring setup data, a standard location for this is provided in the container. Furthermore, an official list of codec identifiers is maintained, meaning all information required to fully support Matroska files is available from one place.
Matroska also has probably the greatest advantage of all : it is in active, wide-spread use. Historically, standards derived from existing practice have proven more successful than those created by a design committee.
Overhead
When designing a container format, one important consideration is that of overhead, i.e. the extra space required in addition to the elementary stream data being combined. For any given container, the overhead can be divided into a fixed part, independent of the total file size, and a variable part growing with increasing file size. The fixed overhead is not of much concern, its relative contribution being negligible for typical file sizes.
The variable overhead in the Ogg format comes from the page headers, mostly from the segment_table field. This field uses a most peculiar encoding, somewhat reminiscent of Roman numerals. In Roman times, numbers were written as a sequence of symbols, each representing a value, the combined value being the sum of the constituent values.
The segment_table field lists the sizes of all packets in the page. Each value in the list is coded as a number of bytes equal to 255 followed by a final byte with a smaller value. The packet size is simply the sum of all these bytes. Any strictly additive encoding, such as this, has the distinct drawback of coded length being linearly proportional to the encoded value. A value of 5000, a reasonable packet size for video of moderate bitrate, requires no less than 20 bytes to encode.
On top of this we have the 27-byte page header which, although paling in comparison to the packet size encoding, is still much larger than necessary. Starting at the top of the list :
- The version field could be disposed of, a single-bit marker being adequate to separate this first version from hypothetical future versions. One of the unused positions in the flags field could be used for this purpose
- A 64-bit granule_position is completely overkill. 32 bits would be more than enough for the vast majority of use cases. In extreme cases, a one-bit flag could be used to signal an extended timestamp field.
- 32-bit elementary stream number ? Are they anticipating files with four billion elementary streams ? An eight-bit field, if not smaller, would seem more appropriate here.
- The 32-bit page_sequence_number is inexplicable. The intent is to allow detection of page loss due to transmission errors. ISO MPEG-TS uses a 4-bit counter per 188-byte packet for this purpose, and that format is used where packet loss actually happens, unlike any use of Ogg to date.
- A mandatory 32-bit checksum is nothing but a waste of space when using a reliable storage/transmission medium. Again, a flag could be used to signal the presence of an optional checksum field.
With the changes suggested above, the page header would shrink from 27 bytes to 12 bytes in size.
We thus see that in an Ogg file, the packet size fields alone contribute an overhead of 1/255 or approximately 0.4%. This is a hard lower bound on the overhead, not attainable even in theory. In reality the overhead tends to be closer to 1%.
Contrast this with the ISO MP4 file format, which can easily achieve an overhead of less than 0.05% with a 1 Mbps elementary stream.
Latency
In many applications end-to-end latency is an important factor. Examples include video conferencing, telephony, live sports events, interactive gaming, etc. With the codec layer contributing as little as 10 milliseconds of latency, the amount imposed by the container becomes an important factor.
Latency in an Ogg-based system is introduced at both the sender and the receiver. Since the page header depends on the entire contents of the page (packet sizes and checksum), a full page of packets must be buffered by the sender before a single bit can be transmitted. This sets a lower bound for the sending latency at the duration of a page.
On the receiving side, playback cannot commence until packets from all elementary streams are available. Hence, with two streams (audio and video) interleaved at the page level, playback is delayed by at least one page duration (two if checksums are verified).
Taking both send and receive latencies into account, the minimum end-to-end latency for Ogg is thus twice the duration of a page, triple if strict checksum verification is required. If page durations are variable, the maximum value must be used in order to avoid buffer underflows.
Minimum latency is clearly achieved by minimising the page duration, which in turn implies sending only one packet per page. This is where the size of the page header becomes important. The header for a single-packet page is 27 + packet_size/255 bytes in size. For a 1 Mbps video stream at 25 fps this gives an overhead of approximately 1%. With a typical audio packet size of 400 bytes, the overhead becomes a staggering 7%. The average overhead for a multiplex of these two streams is 1.4%.
As it stands, the Ogg format is clearly not a good choice for a low-latency application. The key to low latency is small packets and fine-grained interleaving of streams, and although Ogg can provide both of these, by sending a single packet per page, the price in overhead is simply too high.
ISO MPEG-PS has an overhead of 9 bytes on most packets (a 5-byte timestamp is added a few times per second), and Microsoft’s ASF has a 12-byte packet header. My suggestions for compacting the Ogg page header would bring it in line with these formats.
Random access
Any general-purpose container format needs to allow random access for direct seeking to any given position in the file. Despite this goal being explicitly mentioned in the Ogg specification, the format only allows the most crude of random access methods.
While many container formats include an index allowing a time to be directly translated into an offset into the file, Ogg has nothing of this kind, the stated rationale for the omission being that this would require a two-pass multiplexing, the second pass creating the index. This is obviously not true ; the index could simply be written at the end of the file. Those objecting that this index would be unavailable in a streaming scenario are forgetting that seeking is impossible there regardless.
The method for seeking suggested by the Ogg documentation is to perform a binary search on the file, after each file-level seek operation scanning for a page header, extracting the timestamp, and comparing it to the desired position. When the elementary stream encoding allows only certain packets as random access points (video key frames), a second search will have to be performed to locate the entry point closest to the desired time. In a large file (sizes upwards of 10 GB are common), 50 seeks might be required to find the correct position.
A typical hard drive has an average seek time of roughly 10 ms, giving a total time for the seek operation of around 500 ms, an annoyingly long time. On a slow medium, such as an optical disc or files served over a network, the times are orders of magnitude longer.
A factor further complicating the seeking process is the possibility of header emulation within the elementary stream data. To safeguard against this, one has to read the entire page and verify the checksum. If the storage medium cannot provide data much faster than during normal playback, this provides yet another substantial delay towards finishing the seeking operation. This too applies to both network delivery and optical discs.
Although optical disc usage is perhaps in decline today, one should bear in mind that the Ogg format was designed at a time when CDs and DVDs were rapidly gaining ground, and network-based storage is most certainly on the rise.
The final nail in the coffin of seeking is the codec-dependent timestamp format. At each step in the seeking process, the timestamp parsing specified by the codec mapping corresponding the current page must be invoked. If the mapping is not known, the best one can do is skip pages until one with a known mapping is found. This delays the seeking and complicates the implementation, both bad things.
Timestamps
A problem old as multimedia itself is that of synchronising multiple elementary streams (e.g. audio and video) during playback ; badly synchronised A/V is highly unpleasant to view. By the time Ogg was invented, solutions to this problem were long since explored and well-understood. The key to proper synchronisation lies in tagging elementary stream packets with timestamps, packets carrying the same timestamp intended for simultaneous presentation. The concept is as simple as it seems, so it is astonishing to see the amount of complexity with which the Ogg designers managed to imbue it. So bizarre is it, that I have devoted an entire article to the topic, and will not cover it further here.
Complexity
Video and audio decoding are time-consuming tasks, so containers should be designed to minimise extra processing required. With the data volumes involved, even an act as simple as copying a packet of compressed data can have a significant impact. Once again, however, Ogg lets us down. Despite the brevity of the specification, the format is remarkably complicated to parse properly.
The unusual and inefficient encoding of the packet sizes limits the page size to somewhat less than 64 kB. To still allow individual packets larger than this limit, it was decided to allow packets spanning multiple pages, a decision with unfortunate implications. A page-spanning packet as it arrives in the Ogg stream will be discontiguous in memory, a situation most decoders are unable to handle, and reassembly, i.e. copying, is required.
The knowledgeable reader may at this point remark that the MPEG-TS format also splits packets into pieces requiring reassembly before decoding. There is, however, a significant difference there. MPEG-TS was designed for hardware demultiplexing feeding directly into hardware decoders. In such an implementation the fragmentation is not a problem. Rather, the fine-grained interleaving is a feature allowing smaller on-chip buffers.
Buffering is also an area in which Ogg suffers. To keep the overhead down, pages must be made as large as practically possible, and page size translates directly into demultiplexer buffer size. Playback of a file with two elementary streams thus requires 128 kB of buffer space. On a modern PC this is perhaps nothing to be concerned about, but in a small embedded system, e.g. a portable media player, it can be relevant.
In addition to the above, a number of other issues, some of them minor, others more severe, make Ogg processing a painful experience. A selection follows :
- 32-bit random elementary stream identifiers mean a simple table-lookup cannot be used. Instead the list of streams must be searched for a match. While trivial to do in software, it is still annoying, and a hardware demultiplexer would be significantly more complicated than with a smaller identifier.
- Semantically ambiguous streams are possible. For example, the continuation flag (bit 1) may conflict with continuation (or lack thereof) implied by the segment table on the preceding page. Such invalid files have been spotted in the wild.
- Concatenating independent Ogg streams forms a valid stream. While finding a use case for this strange feature is difficult, an implementation must of course be prepared to encounter such streams. Detecting and dealing with these adds pointless complexity.
- Unusual terminology : inventing new terms for well-known concepts is confusing for the developer trying to understand the format in relation to others. A few examples :
Ogg name Usual name logical bitstream elementary stream grouping multiplexing lacing value packet size (approximately) segment imaginary element serving no real purpose granule position timestamp
Final words
We have found the Ogg format to be a dubious choice in just about every situation. Why then do certain organisations and individuals persist in promoting it with such ferocity ?
When challenged, three types of reaction are characteristic of the Ogg campaigners.
On occasion, these people will assume an apologetic tone, explaining how Ogg was only ever designed for simple audio-only streams (ignoring it is as bad for these as for anything), and this is no doubt true. Why then, I ask again, do they continue to tout Ogg as the one-size-fits-all solution they already admitted it is not ?
More commonly, the Ogg proponents will respond with hand-waving arguments best summarised as Ogg isn’t bad, it’s just different. My reply to this assertion is twofold :
- Being too different is bad. We live in a world where multimedia files come in many varieties, and a decent media player will need to handle the majority of them. Fortunately, most multimedia file formats share some basic traits, and they can easily be processed in the same general framework, the specifics being taken care of at the input stage. A format deviating too far from the standard model becomes problematic.
- Ogg is bad. When every angle of examination reveals serious flaws, bad is the only fitting description.
The third reaction bypasses all technical analysis : Ogg is patent-free, a claim I am not qualified to directly discuss. Assuming it is true, it still does not alter the fact that Ogg is a bad format. Being free from patents does not magically make Ogg a good choice as file format. If all the standard formats are indeed covered by patents, the only proper solution is to design a new, good format which is not, this time hopefully avoiding the old mistakes.
-
Android java.lang.UnsatisfiedLinkError : android error for .so libraries
14 septembre 2017, par Burak irenso libraries to my project for ffmpeg camera but I have got some errors when I load the library.
I’m getting error like that "java.lang.UnsatisfiedLinkError : android" .
My .so files directory is src-main-jniLibs-armeabi - so files. When I loading the so file gettting error I can’t load the so file. I have tried many answer but still going this error.
If you want other config files I can load here.
Error log is here also
09-14 17:40:33.739 19728-20196/? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #6
Process: com.leadtimeapp.io.internal.debug, PID: 19728
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.leadtimeapp.io.internal.debug-2/base.apk"],nativeLibraryDirectories=[/data/app/com.leadtimeapp.io.internal.debug-2/lib/arm64, /data/app/com.leadtimeapp.io.internal.debug-2/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]] couldn't find "libjniavformat.so"
at java.lang.Runtime.loadLibrary(Runtime.java:367)
at java.lang.System.loadLibrary(System.java:1076)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:711)
at com.googlecode.javacpp.Loader.load(Loader.java:586)
at com.googlecode.javacpp.Loader.load(Loader.java:540)
at com.googlecode.javacv.cpp.avformat.<clinit>(avformat.java:40)
at com.googlecode.javacv.cpp.avformat.av_register_all(Native Method)
at com.leadtimeapp.io.ffmpeg.NewFFmpegFrameRecorder.<clinit>(NewFFmpegFrameRecorder.java:302)
at com.leadtimeapp.io.ffmpeg.FFmpegRecorderActivity.initVideoRecorder(FFmpegRecorderActivity.java:464)
at com.leadtimeapp.io.ffmpeg.FFmpegRecorderActivity.access$1400(FFmpegRecorderActivity.java:66)
at com.leadtimeapp.io.ffmpeg.FFmpegRecorderActivity$2.doInBackground(FFmpegRecorderActivity.java:368)
at com.leadtimeapp.io.ffmpeg.FFmpegRecorderActivity$2.doInBackground(FFmpegRecorderActivity.java:360)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.leadtimeapp.io.internal.debug-2/base.apk"],nativeLibraryDirectories=[/data/app/com.leadtimeapp.io.internal.debug-2/lib/arm64, /data/app/com.leadtimeapp.io.internal.debug-2/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]] couldn't find "libavformat.so"
at java.lang.Runtime.loadLibrary(Runtime.java:367)
at java.lang.System.loadLibrary(System.java:1076)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:711)
at com.googlecode.javacpp.Loader.load(Loader.java:577)
at com.googlecode.javacpp.Loader.load(Loader.java:540)
at com.googlecode.javacv.cpp.avformat.<clinit>(avformat.java:40)
at com.googlecode.javacv.cpp.avformat.av_register_all(Native Method)
at com.leadtimeapp.io.ffmpeg.NewFFmpegFrameRecorder.<clinit>(NewFFmpegFrameRecorder.java:302)
at com.leadtimeapp.io.ffmpeg.FFmpegRecorderActivity.initVideoRecorder(FFmpegRecorderActivity.java:464)
at com.leadtimeapp.io.ffmpeg.FFmpegRecorderActivity.access$1400(FFmpegRecorderActivity.java:66)
at com.leadtimeapp.io.ffmpeg.FFmpegRecorderActivity$2.doInBackground(FFmpegRecorderActivity.java:368)
at com.leadtimeapp.io.ffmpeg.FFmpegRecorderActivity$2.doInBackground(FFmpegRecorderActivity.java:360)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
09-14 17:40:34.168 19728-19790/? E/NativeCrypto: ssl=0x7f643ae900
cert_verify_callback x509_store_ctx=0x7f76e3e1a0 arg=0x0
09-14 17:40:34.168 19728-19790/? E/NativeCrypto: ssl=0x7f643ae900
cert_verify_callback calling verifyCertificateChain authMethod=ECDHE_RSA
</clinit></clinit></clinit></clinit>My gradle is
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.github.triplet.play'
apply plugin: 'project-report'
def buildVersionCode = new Date().format("yyMMddHHmm",
TimeZone.getTimeZone("Europe/Istanbul")).toInteger()
def buildVersionName = "1.1.2"
def SupportVersion = '25.3.1'
def OkHttpVersion = '3.2.0'
def RetrofitVersion = '2.0.2'
def FacebookVersion = '4.+'
def GSonVersion = '2.6.2'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
playAccountConfigs {
defaultAccountConfig {
...
}
}
defaultConfig {
applicationId "...."
resValue "string", "app_name", "..."
resValue "string", "face_app_id", "...."
minSdkVersion 16
playAccountConfig = playAccountConfigs.defaultAccountConfig
//noinspection OldTargetApi
targetSdkVersion 25
versionCode buildVersionCode
versionName buildVersionName
multiDexEnabled true
renderscriptTargetApi 19
renderscriptSupportModeEnabled true
}
signingConfigs {
....
}
lintOptions {
abortOnError false // true by default
checkAllWarnings false
checkReleaseBuilds false
ignoreWarnings true // false by default
quiet true // false by default
}
sourceSets {
main.jni.srcDirs = []
main.jniLibs.srcDirs = ['libs']
}
buildTypes {
release {
minifyEnabled true
debuggable false
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parent,
output.outputFile.name.replace("-release", "-release-" + buildVersionName + "-" + buildVersionCode)
)
}
}
}
debug {
debuggable true
zipAlignEnabled true
applicationIdSuffix ".debug"
}
productFlavors {
arm7 {
// in the future, ndk.abiFilter might also work
ndk {
abiFilter 'armeabi-v7a'
}
}
arm8 {
ndk {
abiFilters 'arm64-v8a'
}
}
arm {
ndk {
abiFilter 'armeabi'
}
}
x86 {
ndk {
abiFilter 'x86'
}
}
x86_64 {
ndk {
abiFilter 'x86_64'
}
}
mips {
ndk {
abiFilters 'mips', 'mips64'
}
}
universal {
ndk {
abiFilters 'mips', 'mips64', 'x86', 'x86_64'
}
}
}
}
lintOptions {
abortOnError false
checkReleaseBuilds false
checkAllWarnings true
htmlReport true
htmlOutput file("lint-report.html")
checkReleaseBuilds true
disable 'MissingTranslation'
disable 'UnusedResources'
disable 'IconLauncherShape'
disable 'GoogleAppIndexingApiWarning'
disable 'SelectableText'
error 'CommitTransaction'
error 'InconsistentArrays'
error 'Registered'
error 'ManifestOrder'
}
}
play {
track = 'alpha'
}
dependencies {
compile fileTree(dir: 'libs', include: ['.jar', '.so'])
compile files('libs/javacpp.jar')
compile files('libs/javacv.jar')
compile project(':camera')
compile project(':VideoRecorder')
compile("com.android.support:appcompat-v7:$SupportVersion") {
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'support-annotations'
}
compile("com.android.support:cardview-v7:$SupportVersion") {
exclude group: 'com.android.support', module: 'support-annotations'
}
compile("com.android.support:design:$SupportVersion") {
exclude group: 'com.android.support', module: 'support-core-ui'
exclude group: 'com.android.support', module: 'appcompat-v7'
exclude group: 'com.android.support', module: 'support-v4'
}
compile("com.android.support:support-v4:$SupportVersion") {
exclude group: 'com.android.support', module: 'support-media-compat'
exclude group: 'com.android.support', module: 'support-compat'
}
compile('com.android.support:multidex:1.0.1') {
exclude group: 'com.android.support', module: 'support-vector-drawable'
}
compile(group: 'org.bytedeco', name: 'javacv-platform', version: '1.3') {
exclude group: 'org.bytedeco.javacpp-presets'
}
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.2.1-1.3'
compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.2.1-1.3', classifier: 'android-arm'
compile "com.google.code.gson:gson:$GSonVersion"
compile "com.squareup.okhttp3:okhttp:$OkHttpVersion"
compile "com.squareup.retrofit2:retrofit:$RetrofitVersion"
compile "com.facebook.android:facebook-android-sdk:$FacebookVersion"
compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
transitive = true;
}
compile('com.twitter.sdk.android:twitter:2.3.0@aar') {
transitive = true;
}
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.5.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.wdullaer:materialdatetimepicker:2.3.0'
compile 'com.github.zhaokaiqiang.klog:library:1.4.0'
compile 'com.github.filippudak.progresspieview:library:1.0.4'
compile 'com.daimajia.swipelayout:library:1.2.0@aar'
compile 'com.amazonaws:aws-android-sdk-s3:2.4.7'
compile 'io.paperdb:paperdb:1.5'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.jakewharton:butterknife:8.4.0'
compile 'com.flipboard:bottomsheet-core:1.5.0'
compile 'com.flipboard:bottomsheet-commons:1.5.0'
compile 'com.yqritc:android-scalablevideoview:1.0.4'
compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar'
compile 'com.google.android.gms:play-services-gcm:11.0.4'
compile 'me.relex:circleindicator:1.1.8@aar'
compile 'com.github.ihsanbal:scissors:1.1.3'
compile 'org.zakariya.stickyheaders:stickyheaders:0.7.5'
compile 'com.parse.bolts:bolts-android:1.4.0'
compile 'com.parse:parse-android:1.15.8'
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.github.wooplr:Spotlight:1.2.3'
compile 'com.adjust.sdk:adjust-android:4.7.0'
compile 'com.google.android.gms:play-services-analytics:11.0.4'
compile 'com.makeramen:roundedimageview:2.3.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
compile 'com.github.castorflex.verticalviewpager:library:19.0.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
compile 'jp.wasabeef:blurry:2.1.1'
compile 'com.writingminds:FFmpegAndroid:0.3.2'
} -
How to add new pages and menu items to Piwik – Introducing the Piwik Platform
11 septembre 2014, par Thomas Steur — DevelopmentThis is the next post of our blog series where we introduce the capabilities of the Piwik platform (our previous post was How to create a widget). This time you’ll learn how to extend Piwik by adding new pages and menu items. For this tutorial you will need to have basic knowledge of PHP and optionally of Twig which is the template engine we use.
What can be displayed in a page ?
To make it short : You can display any corporate related content, key metrics, news, help pages, custom reports, contact details, information about your server, forms to manage any data and anything else.
Getting started
In this series of posts, we assume that you have already set up your development environment. If not, visit the Piwik Developer Zone where you’ll find the tutorial Setting up Piwik.
To summarize the things you have to do to get setup :
- Install Piwik (for instance via git).
- Activate the developer mode :
./console development:enable --full
. - Generate a plugin :
./console generate:plugin --name="MyControllerPlugin"
. There should now be a folderplugins/MyControllerPlugin
. - And activate the created plugin under Settings => Plugins.
Let’s start creating a page
We start by using the Piwik Console to create a new page :
./console generate:controller
The command will ask you to enter the name of the plugin the controller should belong to. I will simply use the above chosen plugin name “MyControllerPlugin”. There should now be two files
plugins/MyControllerPlugin/Controller.php
andplugins/MyControllerPlugin/templates/index.twig
which both already contain an example to get you started easily :Controller.php
- class Controller extends \Piwik\Plugin\Controller
- {
- public function index()
- {
- 'answerToLife' => 42
- ));
- }
- }
and templates/index.twig
- {% extends 'dashboard.twig' %}
- {% block content %}
- <strong>Hello world!</strong>
- <br/>
- The answer to life is {{ answerToLife }}
- {% endblock %}
Note : If you are generating the Controller before Piwik 2.7.0 the example will look slightly different.
The controller action
index
assigns the view variableanswerToLife
to the view and renders the Twig templatetemplates/index.twig
. Any variable assigned this way can then be used in the view using for example{{ answerToLife }}
.Using a Twig template to generate the content of your page is actually optional : instead feel free to generate any content as desired and return a string in your controller action.
As the above template
index.twig
is extending the dashboard template the Logo as well as the top menu will automatically appear on top of your content which is defined within the blockcontent
.How to display the page within the admin
If you would like to add the admin menu on the left you have to modify the following parts :
- Extend
\Piwik\Plugin\ControllerAdmin
instead of\Piwik\Plugin\Controller
in the fileController.php
. In a future version of Piwik this step will be no longer neccessary, see #6151 - Extend the template
admin.twig
instead ofdashboard.twig
- Define a headline using an H2-element
- {% extends 'admin.twig' %}
- {% block content %}
- <h2>Hello world!</h2>
- <br/>
- The answer to life is {{ answerToLife }}
- {% endblock %}
Note : Often one needs to add a page to the admin to make a plugin configurable. We have a unified solution for this using the Settings API.
How to display a blank page
If you would like to generate a blank page that shows only your content the template should contain only your markup as follows :
- <strong>Hello world!</strong>
- <br/>
- The answer to life is {{ answerToLife }}
Predefined variables, UI components, security and accessing query parameters
In this blog post we only cover the basics to get you started. We highly recommend to read the MVC guide on our developer pages which covers some of those advanced topics. For instance you might be wondering how to securely access
$_GET
or$_POST
parameters, you might want to restrict the content of your page depending on a user role, and much more.If you would like to know how to make use of JavaScript, CSS and Less have a look at our Working with Piwik’s UI guide.
Note : How to include existing UI components such as a site selector or a date selector will be covered in a future blog post. Also, there are default variables assigned to the view depending on the context. A list of those variables that may or may not be defined is unfortunately not available yet but we will catch up on this.
Let’s add a menu item to make the page accessible
So far you have created a page but you can still not access it. Therefore we need to add a menu item to one of the Piwik menus. We start by using the Piwik Console to create a menu template :
./console generate:menu
The command will ask you to enter the name of the plugin the menu should belong to. I will use again the above chosen plugin name “MyControllerPlugin”. There should now be a file
plugins/MyControllerPlugin/Menu.php
which contains an example to get you started easily :Menu.php
- class Menu extends \Piwik\Plugin\Menu
- {
- public function configureUserMenu(MenuUser $menu)
- {
- // reuse an existing category.
- $menu->addManageItem('My User Item', $this->urlForAction('showList'));
- // or create a custom category
- $menu->addItem('My Custom Category', 'My User Item', $this->urlForDefaultAction());
- }
- }
This is only a part of the generated template since all the examples of the different menus are similar. You can add items to four menus :
configureReportingMenu
To add a new item to the reporting menu which includes all the reports like “Actions” and “Visitors”.configureAdminMenu
To add a new item to the admin menu which includes items like “User settings” and “Websites”.configureTopMenu
To add a new item to the top menu which includes items like “All Websites” and “Logout”.configureUserMenu
To add a new item to the user menu which is accessible when clicking on the username on the top right.
In this blog post we will add a new item to the user menu and to do so we adjust the generated template like this :
- class Menu extends \Piwik\Plugin\Menu
- {
- public function configureUserMenu(MenuUser $menu)
- {
- $menu->addManageItem('My User Item', $this->urlForAction($method = 'index'), $orderId = 30);
- }
- }
That’s it. This will add a menu item named “My User Item” to the “Manage” section of the user menu. When a user chooses the menu item, the “index” method of your controller will be executed and your previously created page will be first rendered and then displayed. Optionally, you can define an order to influence the position of the menu item within the manage section. Following this example you can add an item to any menu for any action. I think you get the point !
Note : In Piwik 2.6.0 and before the above example would look like this :
- class Menu extends \Piwik\Plugin\Menu
- {
- public function configureUserMenu(MenuUser $menu)
- {
- $menu->addManageItem('My User Item', array($module = 'MyControllerPlugin', $action = 'index'), $orderId = 30);
- }
- }
How to test a page
After you have created your page you are surely wondering how to test it. A controller should be usually very simple as it is only the connector between model and view. Therefore, we do usually not create unit or integration test for controllers and for the view less than ever. Instead we would create a UI test that takes a screenshot of your page and compares it with an expected screenshot. Luckily, there is already a section UI tests in our Automated tests guide.
Publishing your Plugin on the Marketplace
In case you want to share your page with other Piwik users you can do this by pushing your plugin to a public GitHub repository and creating a tag. Easy as that. Read more about how to distribute a plugin.
Advanced features
Isn’t it easy to create a page ? We never even created a file ! Of course, based on our API design principle “The complexity of our API should never exceed the complexity of your use case.” you can accomplish more if you want : You can make use of Vanilla JavaScript, jQuery, AngularJS, Less and CSS, you can reuse UI components, you can access query parameters and much more.
Would you like to know more about this ? Go to our MVC (Model-View-Controller) and Working with Piwik’s UI guides in the Piwik Developer Zone.
If you have any feedback regarding our APIs or our guides in the Developer Zone feel free to send it to us.