]> git.sesse.net Git - ffmpeg/blob - libavdevice/decklink_dec.cpp
avdevice/decklink: add support for audio and video input selection
[ffmpeg] / libavdevice / decklink_dec.cpp
1 /*
2  * Blackmagic DeckLink output
3  * Copyright (c) 2013-2014 Luca Barbato, Deti Fliegl
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #include <DeckLinkAPI.h>
23
24 #include <pthread.h>
25 #include <semaphore.h>
26
27 extern "C" {
28 #include "config.h"
29 #include "libavformat/avformat.h"
30 #include "libavformat/internal.h"
31 #include "libavutil/common.h"
32 #include "libavutil/imgutils.h"
33 #if CONFIG_LIBZVBI
34 #include <libzvbi.h>
35 #endif
36 }
37
38 #include "decklink_common.h"
39 #include "decklink_dec.h"
40
41 #if CONFIG_LIBZVBI
42 static uint8_t calc_parity_and_line_offset(int line)
43 {
44     uint8_t ret = (line < 313) << 5;
45     if (line >= 7 && line <= 22)
46         ret += line;
47     if (line >= 320 && line <= 335)
48         ret += (line - 313);
49     return ret;
50 }
51
52 int teletext_data_unit_from_vbi_data(int line, uint8_t *src, uint8_t *tgt)
53 {
54     vbi_bit_slicer slicer;
55
56     vbi_bit_slicer_init(&slicer, 720, 13500000, 6937500, 6937500, 0x00aaaae4, 0xffff, 18, 6, 42 * 8, VBI_MODULATION_NRZ_MSB, VBI_PIXFMT_UYVY);
57
58     if (vbi_bit_slice(&slicer, src, tgt + 4) == FALSE)
59         return -1;
60
61     tgt[0] = 0x02; // data_unit_id
62     tgt[1] = 0x2c; // data_unit_length
63     tgt[2] = calc_parity_and_line_offset(line); // field_parity, line_offset
64     tgt[3] = 0xe4; // framing code
65
66     return 0;
67 }
68 #endif
69
70 static void avpacket_queue_init(AVFormatContext *avctx, AVPacketQueue *q)
71 {
72     memset(q, 0, sizeof(AVPacketQueue));
73     pthread_mutex_init(&q->mutex, NULL);
74     pthread_cond_init(&q->cond, NULL);
75     q->avctx = avctx;
76 }
77
78 static void avpacket_queue_flush(AVPacketQueue *q)
79 {
80     AVPacketList *pkt, *pkt1;
81
82     pthread_mutex_lock(&q->mutex);
83     for (pkt = q->first_pkt; pkt != NULL; pkt = pkt1) {
84         pkt1 = pkt->next;
85         av_packet_unref(&pkt->pkt);
86         av_freep(&pkt);
87     }
88     q->last_pkt   = NULL;
89     q->first_pkt  = NULL;
90     q->nb_packets = 0;
91     q->size       = 0;
92     pthread_mutex_unlock(&q->mutex);
93 }
94
95 static void avpacket_queue_end(AVPacketQueue *q)
96 {
97     avpacket_queue_flush(q);
98     pthread_mutex_destroy(&q->mutex);
99     pthread_cond_destroy(&q->cond);
100 }
101
102 static unsigned long long avpacket_queue_size(AVPacketQueue *q)
103 {
104     unsigned long long size;
105     pthread_mutex_lock(&q->mutex);
106     size = q->size;
107     pthread_mutex_unlock(&q->mutex);
108     return size;
109 }
110
111 static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt)
112 {
113     AVPacketList *pkt1;
114
115     // Drop Packet if queue size is > 1GB
116     if (avpacket_queue_size(q) >  1024 * 1024 * 1024 ) {
117         av_log(q->avctx, AV_LOG_WARNING,  "Decklink input buffer overrun!\n");
118         return -1;
119     }
120     /* duplicate the packet */
121     if (av_dup_packet(pkt) < 0) {
122         return -1;
123     }
124
125     pkt1 = (AVPacketList *)av_malloc(sizeof(AVPacketList));
126     if (!pkt1) {
127         return -1;
128     }
129     pkt1->pkt  = *pkt;
130     pkt1->next = NULL;
131
132     pthread_mutex_lock(&q->mutex);
133
134     if (!q->last_pkt) {
135         q->first_pkt = pkt1;
136     } else {
137         q->last_pkt->next = pkt1;
138     }
139
140     q->last_pkt = pkt1;
141     q->nb_packets++;
142     q->size += pkt1->pkt.size + sizeof(*pkt1);
143
144     pthread_cond_signal(&q->cond);
145
146     pthread_mutex_unlock(&q->mutex);
147     return 0;
148 }
149
150 static int avpacket_queue_get(AVPacketQueue *q, AVPacket *pkt, int block)
151 {
152     AVPacketList *pkt1;
153     int ret;
154
155     pthread_mutex_lock(&q->mutex);
156
157     for (;; ) {
158         pkt1 = q->first_pkt;
159         if (pkt1) {
160             q->first_pkt = pkt1->next;
161             if (!q->first_pkt) {
162                 q->last_pkt = NULL;
163             }
164             q->nb_packets--;
165             q->size -= pkt1->pkt.size + sizeof(*pkt1);
166             *pkt     = pkt1->pkt;
167             av_free(pkt1);
168             ret = 1;
169             break;
170         } else if (!block) {
171             ret = 0;
172             break;
173         } else {
174             pthread_cond_wait(&q->cond, &q->mutex);
175         }
176     }
177     pthread_mutex_unlock(&q->mutex);
178     return ret;
179 }
180
181 class decklink_input_callback : public IDeckLinkInputCallback
182 {
183 public:
184         decklink_input_callback(AVFormatContext *_avctx);
185         ~decklink_input_callback();
186
187         virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv) { return E_NOINTERFACE; }
188         virtual ULONG STDMETHODCALLTYPE AddRef(void);
189         virtual ULONG STDMETHODCALLTYPE  Release(void);
190         virtual HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(BMDVideoInputFormatChangedEvents, IDeckLinkDisplayMode*, BMDDetectedVideoInputFormatFlags);
191         virtual HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(IDeckLinkVideoInputFrame*, IDeckLinkAudioInputPacket*);
192
193 private:
194         ULONG           m_refCount;
195         pthread_mutex_t m_mutex;
196         AVFormatContext *avctx;
197         decklink_ctx    *ctx;
198         int no_video;
199         int64_t initial_video_pts;
200         int64_t initial_audio_pts;
201 };
202
203 decklink_input_callback::decklink_input_callback(AVFormatContext *_avctx) : m_refCount(0)
204 {
205     avctx = _avctx;
206     decklink_cctx       *cctx = (struct decklink_cctx *) avctx->priv_data;
207     ctx = (struct decklink_ctx *) cctx->ctx;
208     initial_audio_pts = initial_video_pts = AV_NOPTS_VALUE;
209     pthread_mutex_init(&m_mutex, NULL);
210 }
211
212 decklink_input_callback::~decklink_input_callback()
213 {
214     pthread_mutex_destroy(&m_mutex);
215 }
216
217 ULONG decklink_input_callback::AddRef(void)
218 {
219     pthread_mutex_lock(&m_mutex);
220     m_refCount++;
221     pthread_mutex_unlock(&m_mutex);
222
223     return (ULONG)m_refCount;
224 }
225
226 ULONG decklink_input_callback::Release(void)
227 {
228     pthread_mutex_lock(&m_mutex);
229     m_refCount--;
230     pthread_mutex_unlock(&m_mutex);
231
232     if (m_refCount == 0) {
233         delete this;
234         return 0;
235     }
236
237     return (ULONG)m_refCount;
238 }
239
240 HRESULT decklink_input_callback::VideoInputFrameArrived(
241     IDeckLinkVideoInputFrame *videoFrame, IDeckLinkAudioInputPacket *audioFrame)
242 {
243     void *frameBytes;
244     void *audioFrameBytes;
245     BMDTimeValue frameTime;
246     BMDTimeValue frameDuration;
247
248     ctx->frameCount++;
249
250     // Handle Video Frame
251     if (videoFrame) {
252         AVPacket pkt;
253         av_init_packet(&pkt);
254         if (ctx->frameCount % 25 == 0) {
255             unsigned long long qsize = avpacket_queue_size(&ctx->queue);
256             av_log(avctx, AV_LOG_DEBUG,
257                     "Frame received (#%lu) - Valid (%liB) - QSize %fMB\n",
258                     ctx->frameCount,
259                     videoFrame->GetRowBytes() * videoFrame->GetHeight(),
260                     (double)qsize / 1024 / 1024);
261         }
262
263         videoFrame->GetBytes(&frameBytes);
264         videoFrame->GetStreamTime(&frameTime, &frameDuration,
265                                   ctx->video_st->time_base.den);
266
267         if (videoFrame->GetFlags() & bmdFrameHasNoInputSource) {
268             if (videoFrame->GetPixelFormat() == bmdFormat8BitYUV) {
269             unsigned bars[8] = {
270                 0xEA80EA80, 0xD292D210, 0xA910A9A5, 0x90229035,
271                 0x6ADD6ACA, 0x51EF515A, 0x286D28EF, 0x10801080 };
272             int width  = videoFrame->GetWidth();
273             int height = videoFrame->GetHeight();
274             unsigned *p = (unsigned *)frameBytes;
275
276             for (int y = 0; y < height; y++) {
277                 for (int x = 0; x < width; x += 2)
278                     *p++ = bars[(x * 8) / width];
279             }
280             }
281
282             if (!no_video) {
283                 av_log(avctx, AV_LOG_WARNING, "Frame received (#%lu) - No input signal detected "
284                         "- Frames dropped %u\n", ctx->frameCount, ++ctx->dropped);
285             }
286             no_video = 1;
287         } else {
288             if (no_video) {
289                 av_log(avctx, AV_LOG_WARNING, "Frame received (#%lu) - Input returned "
290                         "- Frames dropped %u\n", ctx->frameCount, ++ctx->dropped);
291             }
292             no_video = 0;
293         }
294
295         pkt.pts = frameTime / ctx->video_st->time_base.num;
296
297         if (initial_video_pts == AV_NOPTS_VALUE) {
298             initial_video_pts = pkt.pts;
299         }
300
301         pkt.pts -= initial_video_pts;
302         pkt.dts = pkt.pts;
303
304         pkt.duration = frameDuration;
305         //To be made sure it still applies
306         pkt.flags       |= AV_PKT_FLAG_KEY;
307         pkt.stream_index = ctx->video_st->index;
308         pkt.data         = (uint8_t *)frameBytes;
309         pkt.size         = videoFrame->GetRowBytes() *
310                            videoFrame->GetHeight();
311         //fprintf(stderr,"Video Frame size %d ts %d\n", pkt.size, pkt.pts);
312
313 #if CONFIG_LIBZVBI
314         if (!no_video && ctx->teletext_lines && videoFrame->GetPixelFormat() == bmdFormat8BitYUV && videoFrame->GetWidth() == 720) {
315             IDeckLinkVideoFrameAncillary *vanc;
316             AVPacket txt_pkt;
317             uint8_t txt_buf0[1611]; // max 35 * 46 bytes decoded teletext lines + 1 byte data_identifier
318             uint8_t *txt_buf = txt_buf0;
319
320             if (videoFrame->GetAncillaryData(&vanc) == S_OK) {
321                 int i;
322                 int64_t line_mask = 1;
323                 txt_buf[0] = 0x10;    // data_identifier - EBU_data
324                 txt_buf++;
325                 for (i = 6; i < 336; i++, line_mask <<= 1) {
326                     uint8_t *buf;
327                     if ((ctx->teletext_lines & line_mask) && vanc->GetBufferForVerticalBlankingLine(i, (void**)&buf) == S_OK) {
328                         if (teletext_data_unit_from_vbi_data(i, buf, txt_buf) >= 0)
329                             txt_buf += 46;
330                     }
331                     if (i == 22)
332                         i = 317;
333                 }
334                 vanc->Release();
335                 if (txt_buf - txt_buf0 > 1) {
336                     int stuffing_units = (4 - ((45 + txt_buf - txt_buf0) / 46) % 4) % 4;
337                     while (stuffing_units--) {
338                         memset(txt_buf, 0xff, 46);
339                         txt_buf[1] = 0x2c; // data_unit_length
340                         txt_buf += 46;
341                     }
342                     av_init_packet(&txt_pkt);
343                     txt_pkt.pts = pkt.pts;
344                     txt_pkt.dts = pkt.dts;
345                     txt_pkt.stream_index = ctx->teletext_st->index;
346                     txt_pkt.data = txt_buf0;
347                     txt_pkt.size = txt_buf - txt_buf0;
348                     if (avpacket_queue_put(&ctx->queue, &txt_pkt) < 0) {
349                         ++ctx->dropped;
350                     }
351                 }
352             }
353         }
354 #endif
355
356         if (avpacket_queue_put(&ctx->queue, &pkt) < 0) {
357             ++ctx->dropped;
358         }
359     }
360
361     // Handle Audio Frame
362     if (audioFrame) {
363         AVPacket pkt;
364         BMDTimeValue audio_pts;
365         av_init_packet(&pkt);
366
367         //hack among hacks
368         pkt.size = audioFrame->GetSampleFrameCount() * ctx->audio_st->codecpar->channels * (16 / 8);
369         audioFrame->GetBytes(&audioFrameBytes);
370         audioFrame->GetPacketTime(&audio_pts, ctx->audio_st->time_base.den);
371         pkt.pts = audio_pts / ctx->audio_st->time_base.num;
372
373         if (initial_audio_pts == AV_NOPTS_VALUE) {
374             initial_audio_pts = pkt.pts;
375         }
376
377         pkt.pts -= initial_audio_pts;
378         pkt.dts = pkt.pts;
379
380         //fprintf(stderr,"Audio Frame size %d ts %d\n", pkt.size, pkt.pts);
381         pkt.flags       |= AV_PKT_FLAG_KEY;
382         pkt.stream_index = ctx->audio_st->index;
383         pkt.data         = (uint8_t *)audioFrameBytes;
384
385         if (avpacket_queue_put(&ctx->queue, &pkt) < 0) {
386             ++ctx->dropped;
387         }
388     }
389
390     return S_OK;
391 }
392
393 HRESULT decklink_input_callback::VideoInputFormatChanged(
394     BMDVideoInputFormatChangedEvents events, IDeckLinkDisplayMode *mode,
395     BMDDetectedVideoInputFormatFlags)
396 {
397     return S_OK;
398 }
399
400 static HRESULT decklink_start_input(AVFormatContext *avctx)
401 {
402     struct decklink_cctx *cctx = (struct decklink_cctx *) avctx->priv_data;
403     struct decklink_ctx *ctx = (struct decklink_ctx *) cctx->ctx;
404
405     ctx->input_callback = new decklink_input_callback(avctx);
406     ctx->dli->SetCallback(ctx->input_callback);
407     return ctx->dli->StartStreams();
408 }
409
410 extern "C" {
411
412 av_cold int ff_decklink_read_close(AVFormatContext *avctx)
413 {
414     struct decklink_cctx *cctx = (struct decklink_cctx *) avctx->priv_data;
415     struct decklink_ctx *ctx = (struct decklink_ctx *) cctx->ctx;
416
417     if (ctx->capture_started) {
418         ctx->dli->StopStreams();
419         ctx->dli->DisableVideoInput();
420         ctx->dli->DisableAudioInput();
421     }
422
423     ff_decklink_cleanup(avctx);
424     avpacket_queue_end(&ctx->queue);
425
426     av_freep(&cctx->ctx);
427
428     return 0;
429 }
430
431 av_cold int ff_decklink_read_header(AVFormatContext *avctx)
432 {
433     struct decklink_cctx *cctx = (struct decklink_cctx *) avctx->priv_data;
434     struct decklink_ctx *ctx;
435     AVStream *st;
436     HRESULT result;
437     char fname[1024];
438     char *tmp;
439     int mode_num = 0;
440     int ret;
441
442     ctx = (struct decklink_ctx *) av_mallocz(sizeof(struct decklink_ctx));
443     if (!ctx)
444         return AVERROR(ENOMEM);
445     ctx->list_devices = cctx->list_devices;
446     ctx->list_formats = cctx->list_formats;
447     ctx->teletext_lines = cctx->teletext_lines;
448     ctx->preroll      = cctx->preroll;
449     ctx->duplex_mode  = cctx->duplex_mode;
450     if (cctx->video_input > 0 && (unsigned int)cctx->video_input < FF_ARRAY_ELEMS(decklink_video_connection_map))
451         ctx->video_input = decklink_video_connection_map[cctx->video_input];
452     if (cctx->audio_input > 0 && (unsigned int)cctx->audio_input < FF_ARRAY_ELEMS(decklink_audio_connection_map))
453         ctx->audio_input = decklink_audio_connection_map[cctx->audio_input];
454     cctx->ctx = ctx;
455
456 #if !CONFIG_LIBZVBI
457     if (ctx->teletext_lines) {
458         av_log(avctx, AV_LOG_ERROR, "Libzvbi support is needed for capturing teletext, please recompile FFmpeg.\n");
459         return AVERROR(ENOSYS);
460     }
461 #endif
462
463     /* Check audio channel option for valid values: 2, 8 or 16 */
464     switch (cctx->audio_channels) {
465         case 2:
466         case 8:
467         case 16:
468             break;
469         default:
470             av_log(avctx, AV_LOG_ERROR, "Value of channels option must be one of 2, 8 or 16\n");
471             return AVERROR(EINVAL);
472     }
473
474     /* List available devices. */
475     if (ctx->list_devices) {
476         ff_decklink_list_devices(avctx);
477         return AVERROR_EXIT;
478     }
479
480     strcpy (fname, avctx->filename);
481     tmp=strchr (fname, '@');
482     if (tmp != NULL) {
483         mode_num = atoi (tmp+1);
484         *tmp = 0;
485     }
486
487     ret = ff_decklink_init_device(avctx, fname);
488     if (ret < 0)
489         return ret;
490
491     /* Get input device. */
492     if (ctx->dl->QueryInterface(IID_IDeckLinkInput, (void **) &ctx->dli) != S_OK) {
493         av_log(avctx, AV_LOG_ERROR, "Could not open output device from '%s'\n",
494                avctx->filename);
495         ret = AVERROR(EIO);
496         goto error;
497     }
498
499     /* List supported formats. */
500     if (ctx->list_formats) {
501         ff_decklink_list_formats(avctx, DIRECTION_IN);
502         ret = AVERROR_EXIT;
503         goto error;
504     }
505
506     if (mode_num > 0) {
507         if (ff_decklink_set_format(avctx, DIRECTION_IN, mode_num) < 0) {
508             av_log(avctx, AV_LOG_ERROR, "Could not set mode %d for %s\n", mode_num, fname);
509             ret = AVERROR(EIO);
510             goto error;
511         }
512     }
513
514     /* Setup streams. */
515     st = avformat_new_stream(avctx, NULL);
516     if (!st) {
517         av_log(avctx, AV_LOG_ERROR, "Cannot add stream\n");
518         ret = AVERROR(ENOMEM);
519         goto error;
520     }
521     st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
522     st->codecpar->codec_id    = AV_CODEC_ID_PCM_S16LE;
523     st->codecpar->sample_rate = bmdAudioSampleRate48kHz;
524     st->codecpar->channels    = cctx->audio_channels;
525     avpriv_set_pts_info(st, 64, 1, 1000000);  /* 64 bits pts in us */
526     ctx->audio_st=st;
527
528     st = avformat_new_stream(avctx, NULL);
529     if (!st) {
530         av_log(avctx, AV_LOG_ERROR, "Cannot add stream\n");
531         ret = AVERROR(ENOMEM);
532         goto error;
533     }
534     st->codecpar->codec_type  = AVMEDIA_TYPE_VIDEO;
535     st->codecpar->width       = ctx->bmd_width;
536     st->codecpar->height      = ctx->bmd_height;
537
538     st->time_base.den      = ctx->bmd_tb_den;
539     st->time_base.num      = ctx->bmd_tb_num;
540
541     if (cctx->v210) {
542         st->codecpar->codec_id    = AV_CODEC_ID_V210;
543         st->codecpar->codec_tag   = MKTAG('V', '2', '1', '0');
544         st->codecpar->bit_rate    = av_rescale(ctx->bmd_width * ctx->bmd_height * 64, st->time_base.den, st->time_base.num * 3);
545     } else {
546         st->codecpar->codec_id    = AV_CODEC_ID_RAWVIDEO;
547         st->codecpar->format      = AV_PIX_FMT_UYVY422;
548         st->codecpar->codec_tag   = MKTAG('U', 'Y', 'V', 'Y');
549         st->codecpar->bit_rate    = av_rescale(ctx->bmd_width * ctx->bmd_height * 16, st->time_base.den, st->time_base.num);
550     }
551
552     avpriv_set_pts_info(st, 64, 1, 1000000);  /* 64 bits pts in us */
553
554     ctx->video_st=st;
555
556     if (ctx->teletext_lines) {
557         st = avformat_new_stream(avctx, NULL);
558         if (!st) {
559             av_log(avctx, AV_LOG_ERROR, "Cannot add stream\n");
560             ret = AVERROR(ENOMEM);
561             goto error;
562         }
563         st->codecpar->codec_type  = AVMEDIA_TYPE_SUBTITLE;
564         st->time_base.den         = ctx->bmd_tb_den;
565         st->time_base.num         = ctx->bmd_tb_num;
566         st->codecpar->codec_id    = AV_CODEC_ID_DVB_TELETEXT;
567         avpriv_set_pts_info(st, 64, 1, 1000000);  /* 64 bits pts in us */
568         ctx->teletext_st = st;
569     }
570
571     av_log(avctx, AV_LOG_VERBOSE, "Using %d input audio channels\n", ctx->audio_st->codecpar->channels);
572     result = ctx->dli->EnableAudioInput(bmdAudioSampleRate48kHz, bmdAudioSampleType16bitInteger, ctx->audio_st->codecpar->channels);
573
574     if (result != S_OK) {
575         av_log(avctx, AV_LOG_ERROR, "Cannot enable audio input\n");
576         ret = AVERROR(EIO);
577         goto error;
578     }
579
580     result = ctx->dli->EnableVideoInput(ctx->bmd_mode,
581                                         cctx->v210 ? bmdFormat10BitYUV : bmdFormat8BitYUV,
582                                         bmdVideoInputFlagDefault);
583
584     if (result != S_OK) {
585         av_log(avctx, AV_LOG_ERROR, "Cannot enable video input\n");
586         ret = AVERROR(EIO);
587         goto error;
588     }
589
590     avpacket_queue_init (avctx, &ctx->queue);
591
592     if (decklink_start_input (avctx) != S_OK) {
593         av_log(avctx, AV_LOG_ERROR, "Cannot start input stream\n");
594         ret = AVERROR(EIO);
595         goto error;
596     }
597
598     return 0;
599
600 error:
601     ff_decklink_cleanup(avctx);
602     return ret;
603 }
604
605 int ff_decklink_read_packet(AVFormatContext *avctx, AVPacket *pkt)
606 {
607     struct decklink_cctx *cctx = (struct decklink_cctx *) avctx->priv_data;
608     struct decklink_ctx *ctx = (struct decklink_ctx *) cctx->ctx;
609     AVFrame *frame = ctx->video_st->codec->coded_frame;
610
611     avpacket_queue_get(&ctx->queue, pkt, 1);
612     if (frame && (ctx->bmd_field_dominance == bmdUpperFieldFirst || ctx->bmd_field_dominance == bmdLowerFieldFirst)) {
613         frame->interlaced_frame = 1;
614         if (ctx->bmd_field_dominance == bmdUpperFieldFirst) {
615             frame->top_field_first = 1;
616         }
617     }
618
619     return 0;
620 }
621
622 } /* extern "C" */