BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / add-ons / media / media-add-ons / video_producer_demo / AddOn.cpp
blobe31709940cc2f5b796815883cb1b793378e6ea99
1 /*
2 Copyright 1999, Be Incorporated. All Rights Reserved.
3 This file may be used under the terms of the Be Sample Code License.
4 */
5 #include <Autolock.h>
6 #include <MediaFormats.h>
7 #include <stdio.h>
8 #include <string.h>
9 #include <unistd.h>
11 #include "AddOn.h"
12 #include "Producer.h"
14 MediaAddOn::MediaAddOn(image_id imid)
15 : BMediaAddOn(imid)
17 /* Customize these parameters to match those of your node */
18 fFlavorInfo.name = (char *)"Demo Video Producer";
19 fFlavorInfo.info = (char *)"Demo Video Producer";
20 fFlavorInfo.kinds = B_BUFFER_PRODUCER | B_CONTROLLABLE;
21 fFlavorInfo.flavor_flags = 0;
22 fFlavorInfo.internal_id = 0;
23 fFlavorInfo.possible_count = 5; // limited to 5 instances (just for testing)
24 fFlavorInfo.in_format_count = 0;
25 fFlavorInfo.in_format_flags = 0;
26 fFlavorInfo.in_formats = NULL;
27 fFlavorInfo.out_format_count = 1;
28 fFlavorInfo.out_format_flags = 0;
29 fMediaFormat.type = B_MEDIA_RAW_VIDEO;
30 fMediaFormat.u.raw_video = media_raw_video_format::wildcard;
31 fMediaFormat.u.raw_video.interlace = 1;
32 fMediaFormat.u.raw_video.display.format = B_RGB32;
33 fFlavorInfo.out_formats = &fMediaFormat;
35 fInitStatus = B_OK;
38 MediaAddOn::~MediaAddOn()
43 status_t
44 MediaAddOn::InitCheck(const char **out_failure_text)
46 if (fInitStatus < B_OK) {
47 *out_failure_text = "Unknown error";
48 return fInitStatus;
51 return B_OK;
54 int32
55 MediaAddOn::CountFlavors()
57 if (fInitStatus < B_OK)
58 return fInitStatus;
60 /* This addon only supports a single flavor, as defined in the
61 * constructor */
62 return 1;
66 * The pointer to the flavor received only needs to be valid between
67 * successive calls to BMediaAddOn::GetFlavorAt().
69 status_t
70 MediaAddOn::GetFlavorAt(int32 n, const flavor_info **out_info)
72 if (fInitStatus < B_OK)
73 return fInitStatus;
75 if (n != 0)
76 return B_BAD_INDEX;
78 /* Return the flavor defined in the constructor */
79 *out_info = &fFlavorInfo;
80 return B_OK;
83 BMediaNode *
84 MediaAddOn::InstantiateNodeFor(
85 const flavor_info *info, BMessage *config, status_t *out_error)
87 VideoProducer *node;
89 if (fInitStatus < B_OK)
90 return NULL;
92 if (info->internal_id != fFlavorInfo.internal_id)
93 return NULL;
95 /* At most one instance of the node should be instantiated at any given
96 * time. The locking for this restriction may be found in the VideoProducer
97 * class. */
98 node = new VideoProducer(this, fFlavorInfo.name, fFlavorInfo.internal_id);
99 if (node && (node->InitCheck() < B_OK)) {
100 delete node;
101 node = NULL;
104 return node;
107 BMediaAddOn *
108 make_media_addon(image_id imid)
110 return new MediaAddOn(imid);